-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiece.py
135 lines (106 loc) · 2.44 KB
/
piece.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from random import randint
from colorama import Fore
class Piece:
def __init__ (self):
self._num = randint (0,5)
self._body = self.makeBody(self._num);
self._x = 4
self._y = 20
self._changed = True
def moveLeft (self):
self._x -= 1
self.setChanged(True)
def moveRight (self):
self._x += 1
self.setChanged(True)
def moveDown (self):
self._y += 1;
self.setChanged(True)
def rotateRight(self):
self._body = self.rotateBody(self._body)
self.setChanged(True)
def getBody(self):
return self._body
def resetPos(self):
self._x=4
self._y=20
def getPos(self):
return {'x': self._x, 'y': self._y}
@staticmethod
def rotateBody (body: list[list[str]]):
def rotate (body):
return list(zip(*body[::-1]))
body = rotate(body)
# Handle issues with rotate line piece
if (len(body) == 4):
if (body[0][2] != ' '):
body = rotate(rotate(body))
elif (body[2][3] != ' '):
body = rotate(body)
return body
def getChanged(self):
return self._changed
def setChanged(self, a: bool):
self._changed = a
@staticmethod
def makeBody (k: list[list[str]]):
body = []
color = Fore.CYAN
match k:
# Line Piece
case 0:
body = [
['','','',''],
['▇','▇','▇','▇'],
['','','',''],
['','','','']
]
# L Right
case 1:
color = Fore.BLUE
body = [
['','',''],
['▇','▇','▇'],
['','','▇']
]
# L Left
case 2:
color = Fore.WHITE
body = [
['','',''],
['▇','▇','▇'],
['▇','','','']
]
# Square
case 3:
color = Fore.YELLOW
body = [
['▇','▇'],
['▇','▇']
]
# S Right
case 4:
color = Fore.GREEN
body = [
['','',''],
['','▇','▇'],
['▇','▇','']
]
# T shape
case 5:
color = Fore.MAGENTA
body = [
['','▇',''],
['▇','▇','▇'],
['','','']
]
# S Left
case 6:
color = Fore.RED
body = [
['','',''],
['▇','▇',''],
['','▇','▇']
]
body = list(map(lambda x: list(map(lambda y: color + y + Fore.RESET if y != '' else ' ', x)), body))
return body