-
Notifications
You must be signed in to change notification settings - Fork 0
/
pill.py
65 lines (56 loc) · 1.49 KB
/
pill.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
from enums import Orientation
from cell import Cell
from views import Pill as View
class Pill:
def __init__(self, other=None):
if other is None:
self.cell1 = Cell()
self.cell2 = Cell()
self.cell1.treat()
self.cell2.treat()
self.cell1.bind_right()
self.cell2.bind_left()
self.rotation = Orientation.LR
else:
self.x = other.x
self.y = other.y
self.cell1 = other.cell1
self.cell2 = other.cell2
self.rotation = Orientation(other.rotation)
def rotate(self, back=False):
rot = self.rotation + (3 if back else 1)
self.rotation = Orientation(rot % 4)
def move(self, dx, dy):
self.x += dx
self.y += dy
def bind_ltr(self):
self.cell1.bind_left()
self.cell2.bind_right()
def bind_rtl(self):
self.cell1.bind_right()
self.cell2.bind_left()
def unbind(self):
self.cell1.unbind()
self.cell2.unbind()
def coords(self):
return self.xy1() + self.xy2()
def xy1(self):
if self.rotation == Orientation.LR:
return self.x, self.y
elif self.rotation == Orientation.DU:
return self.x, self.y
elif self.rotation == Orientation.RL:
return self.x + 1, self.y
elif self.rotation == Orientation.UD:
return self.x, self.y - 1
def xy2(self):
if self.rotation == Orientation.LR:
return self.x + 1, self.y
elif self.rotation == Orientation.DU:
return self.x, self.y - 1
elif self.rotation == Orientation.RL:
return self.x, self.y
elif self.rotation == Orientation.UD:
return self.x, self.y
def __str__(self):
return View.render(self)