Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
 public BattleField(int size)
 {
     _size = size;
     Field = new BattleFieldCells(size);
     _ships = new List<Ship>(ShipsDefaultCollection.Count());
 }