Beyond_Beyaan.StarNode.RemoveNodeAtPosition C# (CSharp) Метод

RemoveNodeAtPosition() публичный Метод

public RemoveNodeAtPosition ( int x, int y ) : void
x int
y int
Результат void
        public void RemoveNodeAtPosition(int x, int y)
        {
            if (nodes != null)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].X <= x && nodes[i].X + nodes[i].Width >= x &&
                        nodes[i].Y <= y && nodes[i].Y + nodes[i].Height >= y)
                    {
                        if (nodes[i].Height == 1 && nodes[i].Width == 1)
                        {
                            nodes.Remove(nodes[i]);
                        }
                        else
                        {
                            nodes[i].RemoveNodeAtPosition(x, y);
                            if (nodes[i].nodes.Count == 0)
                            {
                                nodes.Remove(nodes[i]);
                            }
                        }
                        break;
                    }
                }
            }
        }

Usage Example

Пример #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++;
            }
        }
All Usage Examples Of Beyond_Beyaan.StarNode::RemoveNodeAtPosition