Ejemplo n.º 1
0
        public static Sector Get(Sectors sectors, int sX, int sY)
        {
            var gotSectors = sectors.Where(s => s.X == sX && s.Y == sY).ToList();

            if (!gotSectors.Any())
            {
                throw new GameConfigException("Sector not found:  X: " + sX + " Y: " + sY + " Total Sectors: " + sectors.Count());
            }

            if (gotSectors.Count() > 1)
            {
                throw new GameConfigException("Multiple sectors found. X: " + sX + " Y: " + sY + " Total Sectors: " + sectors.Count());
            }

            //There can only be one active sector
            return(gotSectors.Single());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Legacy code. todo: needs to be rewritten.  Checks all sectors around starbase to see if its a good place to dock.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="sectors"></param>
        /// <returns></returns>
        public bool IsDockingLocation(int i, int j, Sectors sectors)
        {
            //http://stackoverflow.com/questions/3150678/using-linq-with-2d-array-select-not-found
            for (int y = i - 1; y <= i + 1; y++)
            {
                for (int x = j - 1; x <= j + 1; x++)
                {
                    var gotSector = Sectors.GetNoError(x, y, sectors);

                    if (gotSector != null)
                    {
                        if (gotSector.Item == SectorItem.Starbase)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static void SetupNewSector(SectorDef sectorDef, Sectors newSectors, Regions Regions)
        {
            //todo: rewrite this function to get rid of GOTO

StartOver:
            var randomSector = Coordinate.GetRandom();

            if (newSectors.NotFound(randomSector))
            {
                Sectors.SetupRandomRegionDef(sectorDef, Regions);

                var locationDef = new LocationDef(sectorDef.RegionDef, new Coordinate(sectorDef.Sector.X, sectorDef.Sector.Y));
                var newSector   = new Sector(locationDef);
                newSector.Item = sectorDef.Item;

                newSectors.Add(newSector);
            }
            else
            {
                //Console.WriteLine("Sector already Set up: " + sectorDef.Sector.X + "," + sectorDef.Sector.Y);
                goto StartOver;
            }
        }
Ejemplo n.º 4
0
 public int GetStarCount()
 {
     return(Sectors.Count(sector => sector.Item == SectorItem.Star));
 }