Пример #1
0
 public void Register(IGameStateObserver o)
 {
     // Check if the observer is already in the list; if not, add it to the list
     if (!_gameStateObservers.Contains(o))
     {
         _gameStateObservers.Add(o);
     }
 }
Пример #2
0
 public void Unregister(IGameStateObserver o)
 {
     // Remove the observer from the list
     if (_gameStateObservers != null)
     {
         _gameStateObservers.Remove(o);
     }
 }
Пример #3
0
 public void AddObserver(IGameStateObserver ob)
 {
     if (!m_GameStateObserverList.Contains(ob))
     {
         m_GameStateObserverList.Add(ob);
     }
     else
     {
         Log.w("This observer has been added before");
     }
 }
Пример #4
0
 public void RemoveObserver(IGameStateObserver ob)
 {
     if (m_GameStateObserverList.Contains(ob))
     {
         m_GameStateObserverList.Remove(ob);
     }
     else
     {
         Log.w("This observer is not in list");
     }
 }
Пример #5
0
        public static Game Create1v1Game(IPlayer p1, IPlayer p2, IGameStateObserver observer)
        {
            var board = GameBoardFactory.Create(3);
            var game  = new Game(
                board,
                p1,
                p2,
                observer);

            return(game);
        }
Пример #6
0
        /// <summary>
        /// Creates 3x3 game with give player and other player as BOT.
        /// </summary>
        public static Game CreateGameWithBot(IPlayer player, IGameStateObserver observer)
        {
            var board = GameBoardFactory.Create(3);
            var game  = new Game(
                board,
                player,
                new AdvancedBot(player.Id.Other()),
                observer);

            return(game);
        }
Пример #7
0
 public Game(
     GameBoard board,
     IPlayer p1,
     IPlayer p2,
     IGameStateObserver gameObserver)
 {
     this.board              = board;
     this.p1                 = p1;
     this.p2                 = p2;
     this.gameObserver       = gameObserver;
     this.board.GameWon     += OnGameWon;
     this.board.GameTied    += OnGameTied;
     this.board.PlayerMoved += OnPlayerMoved;
 }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameContext" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="persistenceContextProvider">The persistence context provider.</param>
        /// <param name="stateObserver">The state observer.</param>
        /// <param name="mapInitializer">The map initializer.</param>
        public GameContext(GameConfiguration configuration, IPersistenceContextProvider persistenceContextProvider, IGameStateObserver stateObserver, IMapInitializer mapInitializer)
        {
            try
            {
                this.Configuration = configuration;
                this.PersistenceContextProvider = persistenceContextProvider;
                this.mapList      = new Dictionary <ushort, GameMap>();
                this.recoverTimer = new Timer(this.RecoverTimerElapsed, null, this.Configuration.RecoveryInterval, this.Configuration.RecoveryInterval);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }

            this.stateObserver  = stateObserver;
            this.mapInitializer = mapInitializer;
        }
Пример #9
0
 public static void RegisterGameStateObserver(IGameStateObserver observer)
 {
     observers.Add(observer);
 }
Пример #10
0
 /// <summary>
 /// Register an IGameStateObserver. Every registered observer is always
 /// notified of the supported status changes that occur in the game.
 /// </summary>
 /// <param name="observer">The observer to be registered.</param>
 public static void RegisterGameStateObserver(IGameStateObserver observer)
 {
     GameObserver.RegisterGameStateObserver(observer);
 }
Пример #11
0
 public static void RegisterGameStateObserver(IGameStateObserver observer)
 {
     observers.Add(observer);
 }