-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcells.py
71 lines (63 loc) · 2.19 KB
/
cells.py
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
61
62
63
64
65
66
67
68
69
70
from graphics import *
class Cell:
def __init__(self, win=None):
self._x1 = None
self._y1 = None
self._x2 = None
self._y2 = None
self.has_left_wall = True
self.has_right_wall = True
self.has_top_wall = True
self.has_bottom_wall = True
self._win = win
self.visited = False
def draw(self,x1, x2, y1, y2):
if self._win is None:
return
self.clear_cell(x1, x2, y1, 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))
#print("drawing left wall")
self._win.draw_line(line)
if self.has_right_wall:
line = Line(Point(x2,y1), Point(x2,y2))
#print("drawing right wall")
self._win.draw_line(line)
if self.has_top_wall:
line = Line(Point(x2,y1), Point(x1,y1))
#print("drawing top wall")
self._win.draw_line(line)
if self.has_bottom_wall:
line = Line(Point(x1,y2), Point(x2,y2))
#print("drawing bottom wall")
self._win.draw_line(line)
def clear_cell(self, x1, x2, y1, y2):
if self._win is None:
return
self._x1 = x1
self._x2 = x2
self._y1 = y1
self._y2 = y2
line = Line(Point(x1, y1), Point(x1, y2))
self._win.draw_line(line, "white")
line = Line(Point(x2, y1), Point(x2, y2))
self._win.draw_line(line, "white")
line = Line(Point(x1, y1), Point(x2, y1))
self._win.draw_line(line, "white")
line = Line(Point(x1, y2), Point(x2, y2))
self._win.draw_line(line, "white")
def draw_move(self, to_cell, undo=False):
if not undo:
line_colour = "red"
else:
line_colour = "grey"
start_x = (self._x1 + self._x2) // 2
start_y = (self._y1 + self._y2) // 2
end_x = (to_cell._x1 + to_cell._x2) // 2
end_y = (to_cell._y1 + to_cell._y2) // 2
line = Line(Point(start_x, start_y), Point(end_x, end_y))
self._win.draw_line(line, line_colour)