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); }
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); }