Time for action – generating the Maze class
1. In the
Maze.cs
class file, add the following to theFields
region:private Random rand = new Random(); public MazeCell[,] MazeCells = new MazeCell[mazeWidth, mazeHeight];
2. In the
Maze
class constructor, add the following after the call toBuildFloor
Buffer()
:for (int x = 0; x < mazeWidth; x++) for (int z = 0; z < mazeHeight; z++) { MazeCells[x, z] = new MazeCell(); } GenerateMaze();
3. Add a new region to the
Maze
class:#region Maze Generation #endregion
4. Add the
GenerateMaze()
method to the Maze Generation region of theMaze
class:public void GenerateMaze() { for (int x = 0; x < mazeWidth; x++) for (int z = 0; z < mazeHeight; z++) { MazeCells[x, z].Walls[0] = true; MazeCells[x, z].Walls[1] = true; MazeCells[x, z].Walls[2] = true; MazeCells[x, z].Walls[3] = true; MazeCells[x, z].Visited = false; } MazeCells[0,0].Visited = true; EvaluateCell...