static void Main(string[] args) { container.Configure(config => { config.Scan(_ => { _.AssemblyContainingType(typeof(Program)); _.WithDefaultConventions(); }); }); var consolePainter = container.GetInstance <ConsolePainter>(); var fleetBuilder = container.GetInstance <IFleetBuilder>(); var consoleStrategy = container.GetInstance <ConsoleReadShotStrategy>(); var randomStrategy = container.GetInstance <RandomShotStrategy>(); var playerAdmiral = new FleetAdmiral( consoleStrategy, fleetBuilder.BuildFleet(new[] { ShipSize.Battleship, ShipSize.Destroyer, ShipSize.Destroyer }) ); var enemyAdmiral = new FleetAdmiral( randomStrategy, fleetBuilder.BuildFleet(new[] { ShipSize.Battleship, ShipSize.Destroyer, ShipSize.Destroyer }) ); consolePainter.DrawBoards(playerAdmiral, enemyAdmiral); while (true) { playerAdmiral.ShootAt(enemyAdmiral); consolePainter.DrawBoards(playerAdmiral, enemyAdmiral); if (enemyAdmiral.IsDefeated) { break; } enemyAdmiral.ShootAt(playerAdmiral); consolePainter.DrawBoards(playerAdmiral, enemyAdmiral); if (playerAdmiral.IsDefeated) { break; } } consolePainter.DrawSummary(playerAdmiral, enemyAdmiral); Console.ReadKey(); }
public void WhenCreatedFleet_ShouldNotBeDefeated() { var cb = new TestCoordinateBoundary(4, 4); var random = new TestRandomProvider(0); var strategy = new TestShotStrategy(cb); var builder = new FleetBuilder(cb, random); var admiral = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); Assert.False(admiral.IsDefeated); }
public void WhenGivenIncorrectCoordinates_ShouldNotRecordShot() { var cb = new TestCoordinateBoundary(4, 4); var random = new TestRandomProvider(0); var strategy = new TestShotStrategy(cb); var builder = new FleetBuilder(cb, random); var admiral1 = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); var admiral2 = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); strategy.SetCoordinate("xx"); Assert.Throws <BattleCoordinateException>(() => admiral1.ShootAt(admiral2)); Assert.False(admiral2.Fleet.ShotsRecorded.Any()); }
public void WhenRandomlyShot_ShouldRecordRandomShot() { var cb = new TestCoordinateBoundary(4, 4); var random = new TestRandomProvider(0); var strategy = new RandomShotStrategy(cb, random); var builder = new FleetBuilder(cb, random); var admiral1 = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); var admiral2 = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); admiral1.ShootAt(admiral2); Assert.True(admiral2.Fleet.ShotsRecorded.Any()); Assert.True(admiral2.Fleet.ShotsRecorded.First().Key.ToString(cb) == "a1"); }
public void WhenAllShipsSunk_ShouldBeDefeated() { var cb = new TestCoordinateBoundary(4, 1); var random = new TestRandomProvider(0); var strategy = new TestShotStrategy(cb); var builder = new FleetBuilder(cb, random); var admiral1 = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); var admiral2 = new FleetAdmiral(strategy, builder.BuildFleet(new [] { ShipSize.Destroyer })); strategy.SetCoordinate("a1"); admiral1.ShootAt(admiral2); strategy.SetCoordinate("b1"); admiral1.ShootAt(admiral2); strategy.SetCoordinate("c1"); admiral1.ShootAt(admiral2); strategy.SetCoordinate("d1"); admiral1.ShootAt(admiral2); Assert.True(admiral2.IsDefeated); }