Implementing the OverCell and UnderCell Class
Explore how to implement OverCell and UnderCell classes to enable braiding and weaving in maze generation. Understand how these classes interact with the grid to create tunnels and link cells, leveraging helper methods and class polymorphism for flexible maze design.
We'll cover the following...
Walking through OverCell
The following is a start to our new OverCell class. We'll put it in weave_cells.rb later on.
Code explanation
Line 5: Calling super here gets us the default set of neighbors, as computed by our original Cell class. We then append to that list, adding potential targets to tunnel to.
Line 6: Here, we add the northern neighbor of this cell, as long as it is possible to tunnel north.
Next, we'll define the helper methods (can_tunnel_north? and friends). We'll add these after our new neighbours method.
The helper methods
The can_tunnel_north? and friends methods
Here’s where we encode the logic that decides whether or not it’s even possible to tunnel in a given direction. Look at the ...