/// <summary> /// Called when a player identifies him/herself. Will move into a waiting position, then /// if each waiting position is filled, starts a game and nulls each waiting position. /// </summary> /// <param name="player">Player that did gone and named him/herself</param> private void NameSpecified(Connect4ClientConnection player) { lock (this) { if (!isShuttingDown) { needToIdentify.Remove(player); player.NameSpecified -= NameSpecified; if (waiting == null) { waiting = player; } else { Connect4ClientConnection player1 = waiting; waiting = null; player1.Disconnected -= Disconnected; player.Disconnected -= Disconnected; Connect4Game game = new Connect4Game(player1, player, timeLimit, choosingMethod); game.GameHasEnded += GameFinished; games.Add(game); } } } }
/// <summary> /// Called when a game is ended. Associated to an event in the Connect4Game class, /// so that when that game ends, we can remove it from the list (freeing up memory /// for future games). /// </summary> /// <param name="game">The game to be closed</param> private void GameFinished(Connect4Game game) { lock (this) { game.GameHasEnded -= GameFinished; games.Remove(game); } }