From 7d976f2350295748077162e6823a757433fe2df5 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Mon, 12 Feb 2024 23:48:41 +0000 Subject: [PATCH] feat: move Cell class to separate module. --- cell.py | 39 +++++++++++++++++++++++++++++++++++++++ graphics.py | 38 -------------------------------------- main.py | 3 ++- 3 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 cell.py diff --git a/cell.py b/cell.py new file mode 100644 index 0000000..16e48fc --- /dev/null +++ b/cell.py @@ -0,0 +1,39 @@ +from graphics import Window, Point, Line + + +class Cell: + """ + A Cell represents a grid on the maze. + """ + + def __init__( + self, + x1: int, y1: int, + x2: int, y2: int, + window: Window + ): + self.__top_wall_exists = True + self.__bottom_wall_exists = True + self.__left_wall_exists = True + self.__right_wall_exists = True + self.__top_wall = Line(Point(x1, y1), Point(x2, y1)) + self.__bottom_wall = Line(Point(x1, y2), Point(x2, y2)) + self.__left_wall = Line(Point(x1, y1), Point(x1, y2)) + self.__right_wall = Line(Point(x2, y1), Point(x2, y2)) + self.__window = window + + def set_walls(self, top: bool, bottom: bool, left: bool, right: bool): + self.__top_wall_exists = top + self.__bottom_wall_exists = bottom + self.__left_wall_exists = left + self.__right_wall_exists = right + + def draw(self): + if self.__top_wall_exists: + self.__window.draw_line(self.__top_wall) + if self.__bottom_wall_exists: + self.__window.draw_line(self.__bottom_wall) + if self.__left_wall_exists: + self.__window.draw_line(self.__left_wall) + if self.__right_wall_exists: + self.__window.draw_line(self.__right_wall) diff --git a/graphics.py b/graphics.py index 16bdc03..8eda20d 100644 --- a/graphics.py +++ b/graphics.py @@ -86,41 +86,3 @@ class Window: close sets the window to close. """ self.__is_running = False - - -class Cell: - """ - A Cell represents a grid on the maze. - """ - - def __init__( - self, - x1: int, y1: int, - x2: int, y2: int, - window: Window - ): - self.__top_wall_exists = True - self.__bottom_wall_exists = True - self.__left_wall_exists = True - self.__right_wall_exists = True - self.__top_wall = Line(Point(x1, y1), Point(x2, y1)) - self.__bottom_wall = Line(Point(x1, y2), Point(x2, y2)) - self.__left_wall = Line(Point(x1, y1), Point(x1, y2)) - self.__right_wall = Line(Point(x2, y1), Point(x2, y2)) - self.__window = window - - def set_walls(self, top: bool, bottom: bool, left: bool, right: bool): - self.__top_wall_exists = top - self.__bottom_wall_exists = bottom - self.__left_wall_exists = left - self.__right_wall_exists = right - - def draw(self): - if self.__top_wall_exists: - self.__window.draw_line(self.__top_wall) - if self.__bottom_wall_exists: - self.__window.draw_line(self.__bottom_wall) - if self.__left_wall_exists: - self.__window.draw_line(self.__left_wall) - if self.__right_wall_exists: - self.__window.draw_line(self.__right_wall) diff --git a/main.py b/main.py index d5db9cb..877d395 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ -from graphics import Window, Cell +from graphics import Window +from cell import Cell def main():