Exemple #1
0
        public void ResetShouldPutGameIntoCorrectState()
        {
            //arrange
            Game.Move(Move.Center);
            Game.Move(Move.SouthWest);
            Game.Move(Move.Northern);
            Game.Move(Move.Western);
            Game.Move(Move.Southern);

            ClearAllEventsReceived();

            //act
            Game.Reset();

            //assert
            Game.GameBoardString.Should().Be(Board.BoardEmptyString);
            Game.CurrentPlayer.Should().Be(Player.X);
            Game.TotalMovesMade.Should().Be(0);
            Game.MoveHistory.Should().BeEmpty();
            Game.GameState.Should().Be(GameState.InPlay);
            Game.GameIsOver.Should().BeFalse();

            GameStateChangedEventsReceivedList.ShouldAllBeEquivalentTo(new[] {
                new GameStateChangedEventArgs(GameState.InPlay, GameChange.Reset, Player.X)
            });

            GameResetEventsReceivedList.Count.Should().Be(1);
        }
Exemple #2
0
        public void UndoLastMoveShouldUndoLastMove()
        {
            //arrange
            Game.Move(Move.Center);
            Game.Move(Move.SouthWest);
            Game.Move(Move.Northern);
            Game.Move(Move.Western);
            Game.Move(Move.Southern);

            ClearAllEventsReceived();

            //act
            Game.UndoLastMove();

            //assert
            Game.GameBoardString.Should().Be("_X_OX_O__");
            Game.CurrentPlayer.Should().Be(Player.X);
            Game.TotalMovesMade.Should().Be(4);
            Game.MoveHistory.ShouldAllBeEquivalentTo(new[] { Move.Center, Move.SouthWest, Move.Northern, Move.Western });
            Game.GameState.Should().Be(GameState.InPlay);
            Game.GameIsOver.Should().BeFalse();

            GameStateChangedEventsReceivedList.ShouldAllBeEquivalentTo(new[] {
                new GameStateChangedEventArgs(GameState.InPlay, GameChange.UndoMove, Player.X)
            });
        }
Exemple #3
0
        public void MoveForWinShouldWork()
        {
            //arrange
            Game.Move(Move.Center);
            Game.Move(Move.Eastern);
            Game.Move(Move.Northern);
            Game.Move(Move.Western);

            ClearAllEventsReceived();

            var moveToMake = Move.Southern;

            //act
            Game.Move(moveToMake);

            //assert
            Game.TotalMovesMade.Should().Be(5);
            Game.GameState.Should().Be(GameState.XWin);
            Game.MoveHistory.Should().BeEquivalentTo(new[] { Move.Center, Move.Eastern, Move.Northern, Move.Western, Move.Southern });
            Game.GameIsOver.Should().BeTrue();
            Game.GameBoardString.Should().Be("_X_OXO_X_");

            GameStateChangedEventsReceivedList.ShouldAllBeEquivalentTo(new[] {
                new GameStateChangedEventArgs(GameState.XWin, GameChange.Over, Player.O)
            });

            GameOverEventsReceivedList.Count.Should().Be(1);
        }
Exemple #4
0
        public void MoveForInPlayShouldWork()
        {
            //arrange
            var moveToMake = Move.Center;

            //act
            Game.Move(moveToMake);

            //assert
            Game.TotalMovesMade.Should().Be(1);
            Game.GameState.Should().Be(GameState.InPlay);
            Game.MoveHistory.Should().BeEquivalentTo(new[] { moveToMake });
            Game.GameIsOver.Should().BeFalse();
            Game.CurrentPlayer.Should().Be(Player.O);
            Game.GameBoardString.Should().Be("____X____");

            GameStateChangedEventsReceivedList.ShouldAllBeEquivalentTo(new[] {
                new GameStateChangedEventArgs(GameState.InPlay, GameChange.Move, Player.O)
            });
        }
Exemple #5
0
 private void ClearAllEventsReceived()
 {
     GameOverEventsReceivedList.Clear();
     GameResetEventsReceivedList.Clear();
     GameStateChangedEventsReceivedList.Clear();
 }
Exemple #6
0
 private void Game_GameStateChanged(object sender, GameStateChangedEventArgs e)
 {
     GameStateChangedEventsReceivedList.Add(e);
 }