-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
176 lines (151 loc) · 6.23 KB
/
forms.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import block
import pygame
import constants as cst
class Form:
def __init__(self,center,color,surface,board):
self.center=center.copy()
self.surface=surface
self.color=color
self.board = board
self.blocks=[]
def checkLost(self):
for b in self.blocks:
if b.coords[1]<1 or self.board[b.coords[0]][b.coords[1]]!=None:
return True
return False
def moveWith(self,x,y,f=True,draw=True):
if(f):
for b in self.blocks:
if not b.can(b.coords[0]+x,b.coords[1]+y):
return False
if draw:
if(f):
self.delete()
else:
self.delete(cst.GRAY)
for b in self.blocks:
b.moveWith(x,y,False,draw)
self.center[0]+=x
self.center[1]+=y
return True
def delete(self,color=cst.BLACK):
for b in self.blocks:
b.delete(color)
def rotate(self,offset_x = 0, offset_y = 0,draw = True): #clock-wise rotation
for b in self.blocks:
x = b.coords[0]
y = b.coords[1]
center_x = self.center[0]
center_y = self.center[1]
x = x - center_x
y = y - center_y
new_x = center_x - y + offset_x
new_y = center_y + x + offset_y
if not(b.can(new_x,new_y)):
if offset_x==0 and offset_y==0:
offx=[1,-1,0,0,-2,2,1,1,0,0,-1,-1,-1,1,-1,-2,1,2,-2,2]
offy=[0,0,1,-1,0,0,1,-1,2,-2,1,-1,2,-2,-2,1,2,-1,-1,1]
for i in range(len(offx)):
if(self.rotate(offx[i],offy[i],draw)):
return True
return False
else:
return False
if draw:
for b in self.blocks:
b.delete()
for b in self.blocks:
x = b.coords[0]
y = b.coords[1]
center_x = self.center[0]
center_y = self.center[1]
x = x - center_x
y = y - center_y
new_x = center_x - y
new_y = center_y + x
b.move(center_x-y+offset_x,center_y+x+offset_y,False,draw)
self.center[0]+=offset_x
self.center[1]+=offset_y
return True
def lock(self):
if self.checkLost():
return False
for b in self.blocks:
self.board[b.coords[0]] [b.coords[1]] = b
self.board[0][b.coords[1]]+=1
return True
class Square(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.YELLOW,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[1]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
def rotate(self,aux1=None,aux2=None,aux3=None):
return
class L1(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.BLUE,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=2
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[1]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
class L2(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.ORANGE,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=2
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[1]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
class Fulger1(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.RED,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1
center[1]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
class Fulger2(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.GREEN,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
center[1]-=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
class Line(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.CYAN,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=1
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=3
self.blocks.append(block.Block(self.color,center,False,surface, board))
class T(Form):
def __init__(self,center,surface, board):
Form.__init__(self,center,cst.PURPLE,surface, board)
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1;
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]+=2;
self.blocks.append(block.Block(self.color,center,False,surface, board))
center[0]-=1;
center[1]-=1;
self.blocks.append(block.Block(self.color,center,False,surface, board))