checkpoint: setting up breaking of walls

This commit is contained in:
Dan Anglin 2024-02-13 18:06:46 +00:00
parent 6d919a99d6
commit 19a29bbb5b
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 50 additions and 8 deletions

49
cell.py
View file

@ -52,6 +52,8 @@ class Cell:
# A reference to the root Window class for drawing purposes. # A reference to the root Window class for drawing purposes.
self._window = window self._window = window
self.visited = False
def configure_walls( def configure_walls(
self, self,
top: bool = True, top: bool = True,
@ -73,6 +75,13 @@ class Cell:
""" """
return self._centre return self._centre
#def break_walls_r(self, i: int, j: int) -> None:
# self.visited = True
# while True:
# list_i = []
# list_j = []
# break
def draw(self) -> None: def draw(self) -> None:
""" """
draw draws the cell onto the canvas draw draws the cell onto the canvas
@ -81,24 +90,48 @@ class Cell:
return return
if self._top_wall.exists: if self._top_wall.exists:
self._window.draw_line(self._top_wall.line, fill_colour=self._window.cell_grid_colour) self._window.draw_line(
self._top_wall.line,
fill_colour=self._window.cell_grid_colour,
)
else: else:
self._window.draw_line(self._top_wall.line, fill_colour=self._window.background_colour) self._window.draw_line(
self._top_wall.line,
fill_colour=self._window.background_colour,
)
if self._bottom_wall.exists: if self._bottom_wall.exists:
self._window.draw_line(self._bottom_wall.line, fill_colour=self._window.cell_grid_colour) self._window.draw_line(
self._bottom_wall.line,
fill_colour=self._window.cell_grid_colour,
)
else: else:
self._window.draw_line(self._bottom_wall.line, fill_colour=self._window.background_colour) self._window.draw_line(
self._bottom_wall.line,
fill_colour=self._window.background_colour,
)
if self._left_wall.exists: if self._left_wall.exists:
self._window.draw_line(self._left_wall.line, fill_colour=self._window.cell_grid_colour) self._window.draw_line(
self._left_wall.line,
fill_colour=self._window.cell_grid_colour,
)
else: else:
self._window.draw_line(self._left_wall.line, fill_colour=self._window.background_colour) self._window.draw_line(
self._left_wall.line,
fill_colour=self._window.background_colour,
)
if self._right_wall.exists: if self._right_wall.exists:
self._window.draw_line(self._right_wall.line, fill_colour=self._window.cell_grid_colour) self._window.draw_line(
self._right_wall.line,
fill_colour=self._window.cell_grid_colour,
)
else: else:
self._window.draw_line(self._right_wall.line, fill_colour=self._window.background_colour) self._window.draw_line(
self._right_wall.line,
fill_colour=self._window.background_colour,
)
def draw_move(self, to_cell: 'Cell', undo: bool = False) -> None: def draw_move(self, to_cell: 'Cell', undo: bool = False) -> None:
""" """

View file

@ -1,5 +1,6 @@
from typing import List from typing import List
from time import sleep from time import sleep
import random
from graphics import Window from graphics import Window
from cell import Cell from cell import Cell
@ -18,6 +19,7 @@ class Maze:
cell_size_x: int, cell_size_x: int,
cell_size_y: int, cell_size_y: int,
window: Window = None, window: Window = None,
seed=None,
) -> None: ) -> None:
self._x_position = x_position self._x_position = x_position
self._y_position = y_position self._y_position = y_position
@ -26,6 +28,13 @@ class Maze:
self._cell_size_x = cell_size_x self._cell_size_x = cell_size_x
self._cell_size_y = cell_size_y self._cell_size_y = cell_size_y
self._window = window self._window = window
self._seed = None
# Generate the seed if it does not exist
if seed:
self._seed = seed
else:
random.seed(self._seed)
# Create the Maze's cells # Create the Maze's cells
self._cells: List[List[Cell]] = [None for i in range(self._num_cell_rows)] self._cells: List[List[Cell]] = [None for i in range(self._num_cell_rows)]