public void PlaceShipsRandomly() { //wipe cells Field = new BattleFieldCells(_size); foreach (var ship in ShipsDefaultCollection) { var cellsCollection = Field.AsSingleCollection().Where(c => !Field.ProximityCheck(c.Coordinate) && c.State != CellState.ShipDeck).ToList(); if (!cellsCollection.Any()) break; Func<Coordinate> getRandomCoordinate = () => cellsCollection[_random.Next(cellsCollection.Count() - 1)].Coordinate; ship.StartingPoint = getRandomCoordinate(); while (!PlaceShip(ship)) { ship.SetRandomOrientation(_random); ship.StartingPoint = getRandomCoordinate(); } } }
public BattleField(int size) { _size = size; Field = new BattleFieldCells(size); _ships = new List<Ship>(ShipsDefaultCollection.Count()); }