

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Maze Class
incomplete
2: Maze Tests
incomplete
3: Break Entrance and Exit
incomplete
4: Break Walls
incomplete
This lesson's interactive features are locked, please to keep using them
Now we need a Maze class that holds all the cells in the maze in a 2-dimensional grid: a list of lists.
def __init__(
self,
x1: int,
y1: int,
num_rows: int,
num_cols: int,
cell_size_x: float,
cell_size_y: float,
win: Window,
) -> None:It initializes data members for all its inputs
It initializes a self.__cells data member to an empty list (this will hold list of lists of cells)
It calls the self.__create_cells() to create the cells in the maze (we're about to create this method)
It fills in the __cells data member: a 2-dimensional list of Cell objects. It should use the number of columns and rows to figure out how many Cell objects to create.
I made the top level list the columns, and the inner lists the rows. So self.__cells[0][0] is the top left cell, and self.__cells[1][0] is the cell to the right of it.
After creating the cells, it should call the self.__draw_cell() method to draw them on the screen (we're about to create this method)
Calculate the x/y position of the cell based on the i/j position and the cell size
Draw the cell using the Cell's draw() method
Call the self.__animate() method to animate the drawing of the cell (we're about to create this method)
Call the window's redraw() method
Sleep for a short amount of time (I used 0.05 seconds) so that we can actually see the pretty animation
The animate method is what allows us to visualize what the algorithms are doing in real time. It's not exactly performant, but its nice to be able to see what's happening as its happening. Its not only pretty, but its good for debugging! You can speed it up or slow it down by changing the sleep time.