feat: move Cell class to separate module.
This commit is contained in:
parent
14c6f659ff
commit
7d976f2350
3 changed files with 41 additions and 39 deletions
39
cell.py
Normal file
39
cell.py
Normal file
|
@ -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)
|
38
graphics.py
38
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)
|
||||
|
|
3
main.py
3
main.py
|
@ -1,4 +1,5 @@
|
|||
from graphics import Window, Cell
|
||||
from graphics import Window
|
||||
from cell import Cell
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Reference in a new issue