Esempio n. 1
0
        public void GameDetectsDrawStatesCorrectly()
        {
            //When a game is created with a winning game layout
            var selfAdvancingClock = new SelfAdvancingClock();
            var game = new TicTacToeGame("xxxoo    ", new Player(m => m.First()), new Player(m => m.First()), () => selfAdvancingClock.GetTime());

            //Then the game state should reflect this
            var lastLine = game.GameStateAsRenderableString
                           .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                           .Last();

            Assert.AreEqual("x has won the game.", lastLine);
            //And the game should be marked as in progress correctly
            Assert.False(game.IsInProgress);
        }
Esempio n. 2
0
        public void GameDetectsWinStatesCorrectly(string board, bool isComplete, string winner)
        {
            //When a game is created with a game layout
            var selfAdvancingClock = new SelfAdvancingClock();
            var game = new TicTacToeGame(board, new Player(m => m.First()), new Player(m => m.First()), () => selfAdvancingClock.GetTime());

            //Then the game should be marked as in progress correctly
            Assert.AreEqual(!isComplete, game.IsInProgress);

            //And the game state should reflect the result of the game if the game is complete
            if (isComplete)
            {
                var expectedMessage = string.IsNullOrWhiteSpace(winner)
                    ? TicTacToeGame.DrawMessage
                    : string.Format(TicTacToeGame.WinMessage, winner);
                Assert.AreEqual(expectedMessage, ((IRenderableGridGame)game).StatusMessage);
            }
        }
Esempio n. 3
0
        public void PlayersCanMakeMoves()
        {
            //Given two players who play squares in index order
            var player1            = new Player(moves => moves.First());
            var player2            = new Player(moves => moves.First());
            var selfAdvancingClock = new SelfAdvancingClock();
            var game = new TicTacToeGame("         ", player1, player2, () => selfAdvancingClock.GetTime());

            //When the players make moves
            for (var i = 0; i < 4; i++)
            {
                var nextPlayer    = i % 2 == 0 ? player1 : player2;
                var waitingPlayer = i % 2 == 0 ? player2 : player1;
                //Then the next player has available moves
                Assert.IsNotEmpty(game.GetAvailableMoves(nextPlayer));
                //And the other player has no available moves
                Assert.IsEmpty(game.GetAvailableMoves(waitingPlayer));
                nextPlayer.TryToMakeMove(game);
            }
        }