* It will then continue to call itself until it reaches a point * Constructs a room of the maze at the specified i and j positions. If there is already a room, we simply skip onwards. Visit all spaces in the maze at least once. Initialize the maze with no rooms at all (all set to null).
![java maze generator algorithm java maze generator algorithm](https://miro.medium.com/max/824/1*f57vxp2Eg0dB_DuZ8KqHUw.png)
Public static Room generateMaze(int width, int height, Main frame) * frame The JFrame that should be repainting. Public static Room generateMaze(int width, int height) * A solvable maze with the matched width and height. * in terms of number of rooms, and is awlays rectangular. The maze has the specified width and height * Generates a random solvable maze with the top left corner as the start, mazes that are more than two dimensions. The indeces for the different possible directions.
![java maze generator algorithm java maze generator algorithm](https://windows-cdn.softpedia.com/screenshots/Amazing-Maze-Generator_1.png)
Public static final int NUM_DIRECTIONS = 4 Can be changed for mazes that are more than two dimensions. * giving every other piece of the path a random number of exits, until every * then charting a path from the start to the finish (top left to bottom right), then * This class generates a random solvable maze by first filling in a maze with walls, I have a much improved version but it’s significantly more complicated, so I figured now is not the time to show it. This also tends to generates mazes where the solution goes from top-left to bottom-left to bottom-right because it generates it through for loops. And for you experienced JGOers, I know I do some lazy things in this code.
![java maze generator algorithm java maze generator algorithm](https://slidetodoc.com/presentation_image/5e6eac857af95da95640905099c9eee6/image-92.jpg)
See, I can post the whole thing within a single JGO post. The maze generator class is not very long at all.