Пример #1
0
        public void CarveMaze(Point startingPoint)
        {
            var section = new MazeSection(startingPoint, ConsoleColor.White, true);

            Sections.Add(section);

            Carve(startingPoint, section);
            CleanUpDeadEnds();
        }
Пример #2
0
        private void Carve(Point point, MazeSection?section)
        {
            visitedPoints.Add(point);
            map.SetWalkable(point, true);
            map.SetTransparent(point, true);

            map.GetCellAt(point).Type = CellType.Maze;

            if (section == null)
            {
                var sectionColor = new ConsoleColor[] { ConsoleColor.Magenta, ConsoleColor.Yellow, ConsoleColor.Blue, ConsoleColor.Red, ConsoleColor.Green }[rnd.Next(0, 5)];

                section = new MazeSection(point, ConsoleColor.DarkGray);

                Sections.Add(section);
            }

            var directions = new List <Direction> {
                Direction.Right, Direction.Left, Direction.Up, Direction.Down
            }
            .OrderBy(x => Guid.NewGuid());

            foreach (var dir in directions)
            {
                var nextPoint = point.Increment(dir);
                if (IsValid(nextPoint, dir, out var foundRoom))
                {
                    section.Points.Add(nextPoint);
                    var adjacentRooms = GetAdjacentRooms(point);
                    section.AdjacentRooms = section.AdjacentRooms.Union(adjacentRooms)
                                            .ToList();
                    if (section.AdjacentRooms.Count > 2)
                    {
                        Carve(nextPoint, null);
                    }
                    else
                    {
                        Carve(nextPoint, section);
                    }
                }
            }

            //Draw();
        }