示例#1
0
        private Ship BuildShip(ShipBuilder shipBuilder, ShipType shipType)
        {
            var orientation = _random.GetRandomOrientation();

            var ship = shipBuilder
                       .WithOrientation(orientation)
                       .OnPosition(GetRandomFreePosition(shipType, orientation))
                       .Build();

            _occupiedFields.AddRange(ship.Fields);

            return(ship);
        }
示例#2
0
        private IEnumerable <Ship> BuildShips()
        {
            var ships = new List <Ship>();

            foreach (var(shipType, shipsCount) in _shipsConfiguration)
            {
                var shipBuilder = new ShipBuilder(shipType);

                var builtShips = Enumerable.Range(1, shipsCount)
                                 .Select(x => BuildShip(shipBuilder, shipType));

                ships.AddRange(builtShips);
            }

            _occupiedFields.Clear();

            return(ships);
        }