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); } }
public void Unregister(IGameStateObserver o) { // Remove the observer from the list if (_gameStateObservers != null) { _gameStateObservers.Remove(o); } }
public void AddObserver(IGameStateObserver ob) { if (!m_GameStateObserverList.Contains(ob)) { m_GameStateObserverList.Add(ob); } else { Log.w("This observer has been added before"); } }
public void RemoveObserver(IGameStateObserver ob) { if (m_GameStateObserverList.Contains(ob)) { m_GameStateObserverList.Remove(ob); } else { Log.w("This observer is not in list"); } }
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); }
/// <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); }
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; }
/// <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; }
public static void RegisterGameStateObserver(IGameStateObserver observer) { observers.Add(observer); }
/// <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); }