I leaned on some concepts from my CS degree, and implemented a depth-first algorithm, similar to this recursive-backtracker noted on Wikipedia.
Additionally, this makes use of the common
CellGrid class which I created to facilitate navigating a 2D array, and getting neighbors of a particular index.
An interesting implementation note is the treatment of the outer edges. The first and last rows of the 2D Array, as well as the leftmost and rightmost columns are treated as “SOLID”, and thus appear as black squares in the visual drawing. This allowed the code to not worry about
undefined neighbors and treat everything as a
Another aspect to note is that
MazeCell objects only directly own the walls to the right and downward from their center, and “delegate” the wall references for the ones to the left and upward to their respective neighbors.
(No interactivity implemented yet).