예제 #1
0
 public BattleshipGame(
     IConsole console,
     IBattleshipStateBuilder stateBuilder,
     IShowGameState gameShowService)
     : this(console, stateBuilder, gameShowService, stateBuilder.Build())
 {
 }
예제 #2
0
        public void SetUp()
        {
            initialState            = BattleshipGameState.Empty(gridSize);
            initialState.Grid[0][0] = BattleshipGridCell.Ship;
            initialState.Grid[0][1] = BattleshipGridCell.Ship;
            initialState.Grid[0][2] = BattleshipGridCell.Ship;

            state1            = BattleshipGameState.Empty(gridSize);
            state1.Grid[0][0] = BattleshipGridCell.Hit;
            state1.Grid[0][1] = BattleshipGridCell.Ship;
            state1.Grid[0][2] = BattleshipGridCell.Ship;

            state2            = BattleshipGameState.Empty(gridSize);
            state2.Grid[0][0] = BattleshipGridCell.Hit;
            state2.Grid[0][1] = BattleshipGridCell.Hit;
            state2.Grid[0][2] = BattleshipGridCell.Ship;

            state3            = BattleshipGameState.Empty(gridSize);
            state3.Grid[0][0] = BattleshipGridCell.Hit;
            state3.Grid[0][1] = BattleshipGridCell.Hit;
            state3.Grid[0][2] = BattleshipGridCell.Hit;

            _console      = Substitute.For <IConsole>();
            _stateBuilder = Substitute.For <IBattleshipStateBuilder>();
            _stateBuilder.Build().Returns(initialState);
            _gameShowService = Substitute.For <IShowGameState>();

            _serviceUnderTests = new BattleshipGame(_console,
                                                    _stateBuilder,
                                                    _gameShowService);
        }
예제 #3
0
        public void PlayRound_ShowsGame_GivenGuess()
        {
            // arrange
            var guess     = "A1";
            var nextState = new BattleshipGameState();

            _stateBuilder.Build(initialState, guess).Returns(nextState);

            // act
            _serviceUnderTests.PlayRound(guess);

            // assert
            _gameShowService.Received().Show(nextState);
        }
예제 #4
0
        public void PlayRound(string guess)
        {
            try
            {
                _gameState = _stateBuilder.Build(_gameState, guess);

                Show(_gameState);
            }
            catch (InvalidInputException)
            {
                _gameShowService.DisplayInputWarning();
            }
            catch (CellRepetitionException)
            {
                _gameShowService.DisplayRetryWarning();
            }
        }
예제 #5
0
 public void GivenIHavePreviousGameState()
 {
     _state = _stateBuilder.Build();
 }