public void Should_ExecuteCommand_ReturnsGameOver_WhenAllTheShipsAreDestroyed() { // Arrange var sut = new BattleshipController(_fixture.BattleshipPlan()); // Act var result = sut.ExecuteCommand("A1"); result = sut.ExecuteCommand("A2"); result = sut.ExecuteCommand("A3"); result = sut.ExecuteCommand("A4"); // Assert result.ResultType.Should().Be(ExecutionResultType.Hit); result.GameOver.Should().BeTrue(); }
public void Should_ExecuteCommand_ReturnsHitOrMiss_DependsOnGivenCoordinates(string command, ExecutionResultType expected) { // Arrange var sut = new BattleshipController(_fixture.BattleshipPlan()); // Act var result = sut.ExecuteCommand(command); // Assert result.ResultType.Should().Be(expected); }
static void Main(string[] args) { var plan = new BattleshipPlanBuilder(new RandomPlacementStrategy()) .SetDimension(10, 10) .AddShip(ShipType.Battleship) .AddShip(ShipType.Destroyer) .AddShip(ShipType.Destroyer) .Build(); var controller = new BattleshipController(plan); while (true) { Console.Write("Enter your command: "); var command = Console.ReadLine(); if (string.IsNullOrWhiteSpace(command)) { continue; } if (command.Equals("quit", StringComparison.CurrentCultureIgnoreCase)) { Environment.Exit(0); } var result = controller.ExecuteCommand(command); if (result.ResultType != ExecutionResultType.NoExecution) { Console.WriteLine(result.Description); } if (!result.GameOver) { continue; } Console.WriteLine("Game over ..."); Environment.Exit(0); } }