Пример #1
0
        private void FillGalaxyWithStars(int numberOfStars, int minPlanets, int maxPlanets, bool[][] grid, Random r)
        {
            starSystems = new List<StarSystem>();
            _quickLookupSystem = new Dictionary<int, StarSystem>();

            StarNode starTree = new StarNode(0, 0, grid.Length - 1, grid.Length - 1);

            //Set area where stars can be placed (circle, random, star, etc shaped galaxy)
            for (int i = 0; i < grid.Length; i++)
            {
                for (int j = 0; j < grid[i].Length; j++)
                {
                    if (!grid[i][j])
                    {
                        starTree.RemoveNodeAtPosition(i, j);
                    }
                }
            }

            int starId = 0;
            while (starTree.nodes.Count > 0 && numberOfStars > 0)
            {
                int x;
                int y;

                starTree.GetRandomStarPosition(r, out x, out y);

                //int newSize = r.Next(3) + 2;

                Color starColor = Color.White;
                string description = string.Empty;

                int randNum = r.Next(100);

                if (randNum < 30)
                {
                    starColor = Color.Red;
                }
                else if (randNum < 55)
                {
                    starColor = Color.Green;
                }
                else if (randNum < 70)
                {
                    starColor = Color.Yellow;
                }
                else if (randNum < 85)
                {
                    starColor = Color.Blue;
                }
                else if (randNum < 95)
                {
                    starColor = Color.White;
                }
                else
                {
                    starColor = Color.Purple;
                }

                var newStarsystem = new StarSystem(NameGenerator.GetStarName(r), starId, x * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), y * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), starColor, description, minPlanets, maxPlanets, r);
                starSystems.Add(newStarsystem);
                _quickLookupSystem.Add(newStarsystem.ID, newStarsystem);

                bool[][] invalidatedArea = Utility.CalculateDisc(2, 1);

                for (int i = 0; i < invalidatedArea.Length; i++)
                {
                    for (int j = 0; j < invalidatedArea.Length; j++)
                    {
                        int xToInvalidate = (x - 2) + i;
                        int yToInvalidate = (y - 2) + j;

                        starTree.RemoveNodeAtPosition(xToInvalidate, yToInvalidate);
                    }
                }

                numberOfStars--;
                starId++;
            }
        }
Пример #2
0
        /*
         * private bool[][] GenerateCluster(int size)
         * {
         *      //Size is actually a diameter, change to radius
         *      return Utility.CalculateDisc(size / 2, 1);
         * }
         *
         * private bool[][] GenerateRing(int size)
         * {
         *      //Size is actually a diameter, change to radius
         *      bool[][] grid = Utility.CalculateDisc(size / 2, 1);
         *
         *      int quarterSize = size / 4;
         *
         *      bool[][] discToSubtract = Utility.CalculateDisc(quarterSize, 1);
         *
         *      for (int i = 0; i < discToSubtract.Length; i++)
         *      {
         *              for (int j = 0; j < discToSubtract[i].Length; j++)
         *              {
         *                      if (discToSubtract[i][j])
         *                      {
         *                              grid[quarterSize + i][quarterSize + j] = false;
         *                      }
         *              }
         *      }
         *
         *      return grid;
         * }
         *
         * private bool[][] GenerateRandom(int size)
         * {
         *      bool[][] grid = new bool[size][];
         *      for (int i = 0; i < grid.Length; i++)
         *      {
         *              grid[i] = new bool[size];
         *      }
         *
         *      for (int i = 0; i < size; i++)
         *      {
         *              for (int j = 0; j < size; j++)
         *              {
         *                      grid[i][j] = true;
         *              }
         *      }
         *
         *      return grid;
         * }
         *
         * private bool[][] GenerateStar(int size)
         * {
         *      bool[][] grid = new bool[size][];
         *      for (int i = 0; i < grid.Length; i++)
         *      {
         *              grid[i] = new bool[size];
         *      }
         *      int halfSize = size / 2;
         *
         *      for (int i = 0; i < size; i++)
         *      {
         *              for (int j = 0; j < size; j++)
         *              {
         *                      int x = i - halfSize;
         *                      int y = halfSize - j;
         *                      if (x < 0)
         *                      {
         *                              x *= -1;
         *                      }
         *                      if (y < 0)
         *                      {
         *                              y *= -1;
         *                      }
         *                      if ((x * x) * (y * y) <= (size * size * (halfSize / 6)))
         *                      {
         *                              grid[i][j] = true;
         *                      }
         *              }
         *      }
         *
         *      return grid;
         * }
         *
         * private bool[][] GenerateDiamond(int size)
         * {
         *      bool[][] grid = new bool[size][];
         *      for (int i = 0; i < grid.Length; i++)
         *      {
         *              grid[i] = new bool[size];
         *      }
         *      int halfSize = size / 2;
         *
         *      for (int i = 0; i < size; i++)
         *      {
         *              for (int j = 0; j < size; j++)
         *              {
         *                      int x = i - halfSize;
         *                      int y = halfSize - j;
         *                      if (x < 0)
         *                      {
         *                              x *= -1;
         *                      }
         *                      if (y < 0)
         *                      {
         *                              y *= -1;
         *                      }
         *                      if (x + y <= halfSize)
         *                      {
         *                              grid[i][j] = true;
         *                      }
         *              }
         *      }
         *
         *      return grid;
         * }*/
        #endregion

        #region Galaxy Filling Functions
        private void FillGalaxyWithStars(int numberOfStars, int minPlanets, int maxPlanets, bool[][] grid, Random r)
        {
            starSystems        = new List <StarSystem>();
            _quickLookupSystem = new Dictionary <int, StarSystem>();

            StarNode starTree = new StarNode(0, 0, grid.Length - 1, grid.Length - 1);

            //Set area where stars can be placed (circle, random, star, etc shaped galaxy)
            for (int i = 0; i < grid.Length; i++)
            {
                for (int j = 0; j < grid[i].Length; j++)
                {
                    if (!grid[i][j])
                    {
                        starTree.RemoveNodeAtPosition(i, j);
                    }
                }
            }

            int starId = 0;

            while (starTree.nodes.Count > 0 && numberOfStars > 0)
            {
                int x;
                int y;

                starTree.GetRandomStarPosition(r, out x, out y);

                //int newSize = r.Next(3) + 2;

                Color  starColor   = Color.White;
                string description = string.Empty;

                int randNum = r.Next(100);


                if (randNum < 30)
                {
                    starColor = Color.Red;
                }
                else if (randNum < 55)
                {
                    starColor = Color.Green;
                }
                else if (randNum < 70)
                {
                    starColor = Color.Yellow;
                }
                else if (randNum < 85)
                {
                    starColor = Color.Blue;
                }
                else if (randNum < 95)
                {
                    starColor = Color.White;
                }
                else
                {
                    starColor = Color.Purple;
                }

                var newStarsystem = new StarSystem(NameGenerator.GetStarName(r), starId, x * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), y * PARSEC_SIZE_IN_PIXELS + (r.Next(PARSEC_SIZE_IN_PIXELS)), starColor, description, minPlanets, maxPlanets, r);
                starSystems.Add(newStarsystem);
                _quickLookupSystem.Add(newStarsystem.ID, newStarsystem);

                bool[][] invalidatedArea = Utility.CalculateDisc(2, 1);

                for (int i = 0; i < invalidatedArea.Length; i++)
                {
                    for (int j = 0; j < invalidatedArea.Length; j++)
                    {
                        int xToInvalidate = (x - 2) + i;
                        int yToInvalidate = (y - 2) + j;

                        starTree.RemoveNodeAtPosition(xToInvalidate, yToInvalidate);
                    }
                }

                numberOfStars--;
                starId++;
            }
        }