Repository navigation
Expand file tree
/
Copy pathcell.py
More file actions
60 lines (51 loc) · 1.94 KB
/
Copy pathcell.py
File metadata and controls
60 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from graphics import Window, Line, Point
class Cell:
def __init__(self,win: Window = None) -> None:
self.has_left_wall = True
self.has_right_wall = True
self.has_top_wall = True
self.has_bottom_wall = True
self._x1 = None
self._x2 = None
self._y1 = None
self._y2 = None
self.visited = False
self._win = win
def draw(self,x1,y1,x2,y2):
self._x1 = x1
self._x2 = x2
self._y1 = y1
self._y2 = y2
if self.has_left_wall:
line = Line(Point(x1,y1),Point(x1,y2))
self._win.draw_line(line)
else:
line = Line(Point(x1,y1),Point(x1,y2))
self._win.draw_line(line,"white")
if self.has_top_wall:
line = Line(Point(x1,y1),Point(x2,y1))
self._win.draw_line(line)
else:
line = Line(Point(x1,y1),Point(x2,y1))
self._win.draw_line(line,"white")
if self.has_right_wall:
line = Line(Point(x2,y1),Point(x2,y2))
self._win.draw_line(line)
else:
line = Line(Point(x2,y1),Point(x2,y2))
self._win.draw_line(line,"white")
if self.has_bottom_wall:
line = Line(Point(x1,y2),Point(x2,y2))
self._win.draw_line(line)
else:
line = Line(Point(x1,y2),Point(x2,y2))
self._win.draw_line(line,"white")
def draw_move(self,to_cell,undo=False):
half_length = abs(self._x2 - self._x1) // 2
x_center = half_length + self._x1
y_center = half_length + self._y1
half_length2 = abs(to_cell._x2 - to_cell._x1) // 2
x_center2 = half_length2 + to_cell._x1
y_center2 = half_length2 + to_cell._y1
move_line = Line(Point(x_center,y_center),Point(x_center2,y_center2))
self._win.draw_line(move_line,"gray" if undo else "red")