From 696199a0227cfccb2247978b1ba8c1b03f1ae26d Mon Sep 17 00:00:00 2001 From: yuzu-eva Date: Mon, 11 Nov 2024 15:52:22 +0100 Subject: initial commit --- maze.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 maze.py (limited to 'maze.py') diff --git a/maze.py b/maze.py new file mode 100644 index 0000000..71086cb --- /dev/null +++ b/maze.py @@ -0,0 +1,51 @@ +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) -- cgit v1.2.3