コード例 #1
0
ファイル: BattleField.cs プロジェクト: vcartera81/Battle-Sea
        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();
                }
            }
        }
コード例 #2
0
ファイル: BattleField.cs プロジェクト: vcartera81/Battle-Sea
 public BattleField(int size)
 {
     _size = size;
     Field = new BattleFieldCells(size);
     _ships = new List<Ship>(ShipsDefaultCollection.Count());
 }