Example #1
0
        public void Factory_creates_destroyer_with_valid_starting_position()
        {
            var factory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var startingPosition = new Position(3, 3);
            var ship             = factory.CreateAt(startingPosition);

            Assert.That(ship.StartPosition, Is.EqualTo(startingPosition));
        }
Example #2
0
        public void Generates_valid_ship_when_ship_position_exceeds_board_size()
        {
            // Ship at (7, 7) won't be created. Only (3, 3) will be created.
            var service = new ShipGenerationService(boardSize, GetRandomPositionGenerator(7, 7, 3, 3));

            var destroyerShipFactory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var existingShip = new HorizontalBattleship(new Position(1, 1));
            var ships        = service.GenerateShips(destroyerShipFactory, 1, new[] { existingShip });

            Assert.That(ships, Has.One.Items);

            Assert.That(ships[0].StartPosition, Is.EqualTo(new Position(3, 3)));
        }
Example #3
0
        public void Generates_valid_ship_when_ship_already_exists()
        {
            // Starting point of both ships is (1, 1) so they must overlaps.
            var service = new ShipGenerationService(boardSize, GetRandomPositionGenerator(1, 1, 4, 4));

            var destroyerShipFactory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var existingShip = new HorizontalBattleship(new Position(1, 1));
            var ships        = service.GenerateShips(destroyerShipFactory, 1, new[] { existingShip });

            Assert.That(ships, Has.One.Items);

            Assert.That(ships[0].StartPosition, Is.EqualTo(new Position(4, 4)));
        }
Example #4
0
        public void Generates_valid_ships_when_first_overlaps_with_second()
        {
            // Starting point of both ships is (1, 2) so they must overlaps.
            var service = new ShipGenerationService(boardSize, GetRandomPositionGenerator(1, 2, 1, 2, 4, 4));

            var destroyerShipFactory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var ships = service.GenerateShips(destroyerShipFactory, 2, Array.Empty <IShip>());

            Assert.That(ships, Has.Exactly(2).Items);

            Assert.That(ships[0].StartPosition, Is.EqualTo(new Position(1, 2)));
            Assert.That(ships[1].StartPosition, Is.EqualTo(new Position(4, 4)));
        }
Example #5
0
        public void Generates_valid_ship_when_there_are_no_ships()
        {
            var service = new ShipGenerationService(boardSize, GetRandomPositionGenerator(1, 2));

            var destroyerShipFactory = new DestroyerFactory(new DeterministicModuloRandomNumberGenerator());

            var ships = service.GenerateShips(destroyerShipFactory, 1, Array.Empty <IShip>());

            Assert.That(ships, Has.One.Items);

            var ship = ships[0];

            Assert.That(ship.StartPosition, Is.EqualTo(new Position(1, 2)));
        }
Example #6
0
        public void Factory_creates_valid_horizontal_destroyer()
        {
            var randomNumberGenerator = new DeterministicModuloRandomNumberGenerator();

            var factory = new DestroyerFactory(randomNumberGenerator);

            var ship = factory.CreateAt(new Position(3, 3));

            var expectedPositions = new[]
            {
                new Position(3, 3),
                new Position(4, 3),
                new Position(5, 3),
                new Position(6, 3),
            };

            Assert.That(ship.Positions, Has.Exactly(4).Items);
            Assert.That(ship.Positions, Is.EquivalentTo(expectedPositions));
        }
 public ShipFactory()
 {
     _rangerFactory    = new RangerFactory();
     _destroyerFactory = new DestroyerFactory();
 }
 public DestroyersPool(DestroyerFactory factory)
 {
     _destroyerFactory = factory;
     data = new List <Entity?>();
 }