public BattleshipGame( IConsole console, IBattleshipStateBuilder stateBuilder, IShowGameState gameShowService) : this(console, stateBuilder, gameShowService, stateBuilder.Build()) { }
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); }
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); }
public void PlayRound(string guess) { try { _gameState = _stateBuilder.Build(_gameState, guess); Show(_gameState); } catch (InvalidInputException) { _gameShowService.DisplayInputWarning(); } catch (CellRepetitionException) { _gameShowService.DisplayRetryWarning(); } }
public void GivenIHavePreviousGameState() { _state = _stateBuilder.Build(); }