from cell import Cell import time class Maze: def __init__( self, x1, y1, num_rows, num_cols, cell_size_x, cell_size_y, win=None ): self._cells = [] self._x1 = x1 self._y1 = y1 self._num_rows = num_rows self._num_cols = num_cols self._cell_size_x = cell_size_x self._cell_size_y = cell_size_y self._win = win self._create_cells() self._break_entrance_and_exit() def _create_cells(self): self._cells = [[Cell(self._win)]*self._num_rows for i in range(self._num_cols)] for i in range(self._num_cols): for j in range(self._num_rows): self._draw_cell(i, j) def _draw_cell(self, i, j): if self._win is None: return x1 = self._x1 + i * self._cell_size_x y1 = self._y1 + j * self._cell_size_y x2 = x1 + self._cell_size_x y2 = y1 + self._cell_size_x self._cells[i][j].draw(x1, y1, x2, y2) self._animate() def _animate(self): self._win.redraw() time.sleep(0.01) def _break_entrance_and_exit(self): self._cells[0][0].twall = False self._draw_cell(0, 0) self._cells[-1][-1].bwall = False self._draw_cell(self._num_cols-1, self._num_rows-1)