Implementing a Mask
Explore how to implement a Mask class that controls which cells are included in a maze grid. Understand how to subclass the grid to use masks for creating mazes fit to specific shapes and simplify maze algorithms by automating cell inclusion.
We'll cover the following...
The Mask class
Let’s create a Mask class that will encapsulate the on-off state of each cell in our grid. That is to say, for each cell in the grid, our mask should be able to tell us whether or not it should be included in the maze. The following implementation does this by keeping a separate two-dimensional array of Boolean values, where false means the corresponding cell is “off the grid.” Let's look at the code below.
Code explanation
Lines 5–8: The initialize constructor is pretty straightforward, just recording the dimensions of the mask and creating a two-dimensional array of Boolean values, indicating which cells are on (enabled) and which are off (disabled).
Lines 10–20: These two methods query and modify ...