public ChessGameSession(IPlayer playerOne, IPlayer playerTwo, IChessGameFactory chessGameFactory) { lock (playerOne) { lock (playerTwo) { if (playerOne.GameSessionGUID != Guid.Empty || playerTwo.GameSessionGUID != Guid.Empty) { throw new InvalidOperationException("Player is already assigned to a game session."); } PlayerOne = playerOne; PlayerTwo = playerTwo; PlayerOne.AddToGame(GUID, new PlayerType <ChessColor>(ChessColor.White)); PlayerTwo.AddToGame(GUID, new PlayerType <ChessColor>(ChessColor.Black)); game = chessGameFactory.Create(); } } }
public GameSessionFactory(IChessGameFactory chessGameFactory) { this.chessGameFactory = chessGameFactory; }