Terrarium.Game.GameEngine.findEmptyPosition C# (CSharp) Метод

findEmptyPosition() приватный Метод

Finds a location within the current game world where no organisms exist.
private findEmptyPosition ( int cellRadius, Point preferredGridPoint ) : Point
cellRadius int The cell radius of the new creature to be inserted.
preferredGridPoint Point The perferred location for the new creature.
Результат Point
        private Point findEmptyPosition(int cellRadius, Point preferredGridPoint)
        {
            Point newLocation = preferredGridPoint == Point.Empty
                                    ? new Point(_random.Next(cellRadius, GridWidth - 1 - cellRadius),
                                                _random.Next(cellRadius, GridHeight - 1 - cellRadius))
                                    : preferredGridPoint;

            int retry = 20;
            while (retry > 0 &&
                   _newWorldState.FindOrganismsInCells(newLocation.X - cellRadius, newLocation.X + cellRadius,
                                                      newLocation.Y - cellRadius, newLocation.Y + cellRadius).Count != 0)
            {
                newLocation = new Point(_random.Next(cellRadius, GridWidth - 1 - cellRadius),
                                        _random.Next(cellRadius, GridHeight - 1 - cellRadius));
                retry--;
            }

            // If we couldn't find a spot delete the organism
            return retry == 0
                       ? Point.Empty
                       : new Point(newLocation.X << EngineSettings.GridWidthPowerOfTwo,
                                   newLocation.Y << EngineSettings.GridHeightPowerOfTwo);
        }