Im currently trying to create a Dungeon Generator . First I place randomly some rooms. Right after that I dig in a randomized maze.
But sometimes it happens that some rooms or even some maze paths are unreachable.
Is there any way to avoid that ? Are there any good Methods for avoiding that ? Any ideas or examples?
Im currently doing it like so (pseudocode) :
Pick a random Number of rooms
Create an arraylist for those rooms
Pick random Positions with random sizes
Try to place all those rooms without overlapping and add them to the list.
-- Room placement Done --
-- Maze Generation Begins --
Loop over the whole Map, if Theres an empty tile ( No wall, No floor and No paths) than Beginn to grow the maze .
When the Statement above ist true, than create a 'Cell arraylist' and put the 'start' cell into it with the coords of the empty tile above . ( A cell just contains x and y coords) .
While the cell list isnt empty, Pick the latest cell (cellsList.Size()-1) and Check the possible direction it Can move. If Theres just empty space in that direction ( No wall, No floor and No paths) than the direction is true.
Pick a random Number and Check for every direction if the assigned Number fits with the random one. If it fits, then dig into that direction and create a new cell at the End . If Not redo this step until one paths ist diged Out.
At least kill 'Dead ends'. Those path tiles which are surounded by 3 empty tiles or those which are completly isolated.
I Hope I mentioned everything . Im currently at my phone and cant acess my Files at my Home PC :/ im gonna Update this later when im Back Home.