Esempio n. 1
0
        public int CheckForExisting()
        {
            int sum = 0;

            for (int y = 0; y < Size; y++)
            {
                for (int x = 0; x < Size; x++)
                {
                    if (_multiArea.Contains(new Point(x, y)))
                    {
                        sum++;
                    }
                }
            }

            return(sum);
        }
Esempio n. 2
0
        private Area?Visit(Point position)
        {
            // Don't bother allocating a MapArea, because the starting point isn't valid.
            if (!AreasView[position])
            {
                return(null);
            }

            // Can't be in multiple areas
            if (_foundAreas.Contains(position))
            {
                return(null);
            }

            var stack = new Stack <Point>();
            var area  = new Area();

            _foundAreas.Add(area);

            stack.Push(position);

            while (stack.Count != 0)
            {
                position = stack.Pop();
                // Already visited, or not part of any mapArea.  Also only called from functions that have allocated
                // visited
                if (area.Contains(position) || !AreasView[position])
                {
                    continue;
                }

                area.Add(position);

                foreach (var c in AdjacencyMethod.Neighbors(position))
                {
                    // Out of bounds, thus not actually a neighbor
                    if (c.X < 0 || c.Y < 0 || c.X >= AreasView.Width || c.Y >= AreasView.Height)
                    {
                        continue;
                    }

                    if (AreasView[c] && !area.Contains(c))
                    {
                        stack.Push(c);
                    }
                }
            }

            return(area);
        }