Beispiel #1
0
        private static void CarvePassages(Maze grid, int currentX, int currentY)
        {
            MazeRenderer.RenderMaze(grid, currentX, currentY);
            var dir        = (Direction[])Enum.GetValues(typeof(Direction));
            var directions = dir.OrderBy(x => rand.Next());

            foreach (var direction in directions)
            {
                int nextX = currentX + Maze.OffsetX(direction);
                int nextY = currentY + Maze.OffsetY(direction);

                if (!grid.ValidX(nextX) || !grid.ValidY(nextY))
                {
                    continue;
                }

                if (grid.HasDoors(nextY, nextX))
                {
                    continue;
                }

                grid.CreateDoor(currentY, currentX, direction);
                grid.CreateDoor(nextY, nextX, Maze.Opposite(direction));
                CarvePassages(grid, nextX, nextY);
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            int dimen = 25;

            Console.Clear();
            Console.CursorVisible = false;
            //while(true)
            {
                var maze = MazeGenerator.GenerateMaze(dimen, dimen);
                var path = MazeSolver.SolveMaze(maze);
                MazeRenderer.RenderMaze(maze, path);
            }
        }