/// <summary> /// build the 3d maze, according to the size of the maze. it calls to maze2d that build /// for every layer maze2d. /// </summary> /// <param name="x">dim X of the maze</param> /// <param name="y">dim Y of the maze</param> /// <param name="z">dim Z of the maze</param> /// <returns>maze 3d</returns> public override Maze generate(int x, int y, int z) { MyMaze3dGenerator g = new MyMaze3dGenerator(); x = x / 2 + 1; y = y / 2 + 1; Maze3d maze3d = new Maze3d(x, y, z); for (int layer = 0; layer < maze3d.MZ; layer++) { Maze2d maze2d = new Maze2d(x, y, layer); g.generateMaze2d(maze2d); maze3d.MAZE3dArray.Add(maze2d); // maze3d.finalGoalPosition(maze2d.getStartPosition()); // maze3d.getGoalPosition().Z = maze3d.MZ - 1; if (layer == 0) { maze3d.setStartPosition(maze2d.getStartPosition()); } if (layer == maze3d.MZ - 1) { maze3d.finalGoalPosition(maze2d.getGoalPosition()); maze3d.getGoalPosition().Z = maze3d.MZ - 1; } } return(maze3d); }
/// <summary> /// print the maze2d for each layer in maze3d /// </summary> /// <param name="maze2d">return maze2d</param> public void printMaze2d(Maze2d maze2d) { string wall = "█"; string path = " "; string start = "S"; string end = "E"; for (int row = 0; row < MX * 2 - 1; row++) { for (int column = 0; column < MY * 2 - 1; column++) { if (maze2d.MAZE2d[row, column] == 1) { Console.BackgroundColor = ConsoleColor.White; //// Console.Write(" "); //// //Console.Write("{0}", wall); } else { if (row == maze2d.getStartPosition().X&& column == maze2d.getStartPosition().Y&& maze2d.MZ == 0) { Console.BackgroundColor = ConsoleColor.DarkGreen;//// Console.Write(" {0}", start); } else { if (row == maze2d.getGoalPosition().X&& column == maze2d.getGoalPosition().Y&& maze2d.MZ == MZ - 1) { Console.BackgroundColor = ConsoleColor.DarkGreen;//// Console.Write(" {0}", end); } else { Console.BackgroundColor = ConsoleColor.DarkRed;//// Console.Write(" {0}", path); } } } } Console.WriteLine(); } Console.BackgroundColor = ConsoleColor.Black; Console.WriteLine(); }