-
Notifications
You must be signed in to change notification settings - Fork 1
/
tetrisOOPs.py
231 lines (171 loc) · 6.98 KB
/
tetrisOOPs.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import pygame
import random as rn
import numpy as np
from terminoes import S, Z, I, O, J, L, T
from resources import *
from config import *
from ghostPieces import GhostPieces
from tetraminoesController import tetraminoesController
pygame.init()
surface = pygame.display.set_mode((W + 50, H))
pygame.display.set_caption('Tetris Game')
font = pygame.font.Font('freesansbold.ttf', 32)
gameOver = 0
def buttonNames(x, y, content):
text = font.render(content, True, (255, 255, 255))
surface.blit(text, (x, y))
def main(level):
global score
global run
global locked
global speed
global curPiece
global nxtPiece
score = 0
speed /= level
run = True
curH = 50; curW = 180 + 50
global gameOver
curPiece = rn.randint(0, 6)
nxtPiece = rn.randint(0, 6)
r = 0
controller = tetraminoesController(30, H, W, locked, allPiece, allColors, curPiece, nxtPiece, r, run, score, speed, gameOver)
controller.gameOver = 0
curEvent = -1
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
curEvent = 1
elif event.key == pygame.K_RIGHT:
curEvent = 2
elif event.key == pygame.K_UP:
curEvent = 3
elif event.key == pygame.K_DOWN:
curEvent = 4
# pygame.draw.rect()
surface.fill((50, 0, 100))
pygame.draw.rect(surface, (50, 200, 0), (42, 42, 370, 670), width = 2, border_radius=9)
buttonNames(500, 200, "Next")
buttonNames(500, 230, "Piece")
controller.nextPiece()
buttonNames(500, 500, "Score")
buttonNames(500, 550, str(score))
controller.drawGrid()
curH, curW, score = controller.pieceFall(curH, curW, curEvent, score)
curEvent = -1
# print(curH)
if controller.gameOver == 1:
break
pygame.display.update()
outro()
return 1
def outro():
global run
img = pygame.image.load("gameover.webp").convert()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
surface.fill((0, 0, 0))
surface.blit(img, (-25, 0))
mousePress = pygame.mouse.get_pressed()
mousePos = pygame.mouse.get_pos()
pygame.draw.rect(surface, (0, 255, 0), (200, 540, 250, 100), border_radius=9)
pygame.draw.rect(surface, (112,128,144), (200, 540, 250, 100), border_radius=9)
buttonNames(200 + 43, 540 + 40, "Play")
buttonNames(200 + 123, 540 + 40, "Again")
buttonNames(250, 460, "Score: " + str(score))
buttonNames(190, 680, "With Great Efforts")
buttonNames(165, 720, "Comes Great Success")
if 540 < mousePos[1] < 640 and 220 < mousePos[0] < 470:
pygame.draw.rect(surface, (50, 0, 100), (200, 540, 250, 100), border_radius=9)
pygame.draw.rect(surface, (50, 200, 0), (200 - 10, 540 - 5, 270, 110), border_radius=9)
buttonNames(200 + 43, 540 + 40, "Play")
buttonNames(200 + 123, 540 + 40, "Again")
if mousePress[0]:
intro()
run = False
pygame.display.update()
intro()
return 0
def intro():
pygame.time.wait(500)
global run
sts = 0
img = pygame.image.load("doodle.webp").convert()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
mousePress = pygame.mouse.get_pressed()
mousePos = pygame.mouse.get_pos()
surface.fill((50, 0, 100))
# img = pygame.transform.scale(img, (400,1000))
surface.blit(img, (0, 0))
# (112,128,144)
pygame.draw.rect(surface, (0, 255, 0), (220, 120, 200, 100), border_radius=9)
pygame.draw.rect(surface, (112,128,144), (220, 120, 200, 100), border_radius=9)
buttonNames(220 + 60, 120 + 40, "Easy")
pygame.draw.rect(surface, (255, 165, 0), (220, 330, 200, 100), border_radius=9)
pygame.draw.rect(surface, (112,128,144), (220, 330, 200, 100), border_radius=9)
buttonNames(220 + 40, 330 + 40, "Medium")
pygame.draw.rect(surface, (255, 50, 0), (220, 540, 200, 100), border_radius=9)
pygame.draw.rect(surface, (112,128,144), (220, 540, 200, 100), border_radius=9)
buttonNames(220 + 60, 540 + 40, "Hard")
if 120 < mousePos[1] < 220 and 220 < mousePos[0] < 420:
pygame.draw.rect(surface, (50, 0, 100), (220, 120, 200, 100), border_radius=9)
pygame.draw.rect(surface, (50, 200, 0), (220 - 10, 120 - 5, 220, 110), border_radius=9)
buttonNames(220 + 60, 120 + 40, "Easy")
if mousePress[0]:
main(1)
elif 330 < mousePos[1] < 530 and 220 < mousePos[0] < 420:
pygame.draw.rect(surface, (50, 0, 100), (220, 330, 200, 100), border_radius=9)
pygame.draw.rect(surface, (200, 150, 30), (220 - 10, 330 - 5, 220, 110), border_radius=9)
buttonNames(220 + 40, 330 + 40, "Medium")
if mousePress[0]:
main(2)
elif 540 < mousePos[1] < 640 and 220 < mousePos[0] < 420:
pygame.draw.rect(surface, (50, 0, 100), (220, 540, 200, 100), border_radius=9)
pygame.draw.rect(surface, (220, 50, 50), (220 - 10, 540 - 5, 220, 110), border_radius=9)
buttonNames(220 + 60, 540 + 40, "Hard")
if mousePress[0]:
main(3)
# if sts == 1:
# sts = outro()
pygame.display.update()
def welcome():
global run
img = pygame.image.load("tetris.webp").convert()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
surface.fill((0, 0, 0))
img = pygame.transform.scale(img, (700,600))
surface.blit(img, (0, 0))
mousePress = pygame.mouse.get_pressed()
mousePos = pygame.mouse.get_pos()
pygame.draw.rect(surface, (0, 255, 0), (220, 540, 250, 100), border_radius=9)
pygame.draw.rect(surface, (112,128,144), (220, 540, 250, 100), border_radius=9)
buttonNames(220 + 43, 540 + 40, "Start")
buttonNames(220 + 129, 540 + 40, "Play")
if 540 < mousePos[1] < 640 and 220 < mousePos[0] < 470:
pygame.draw.rect(surface, (50, 0, 100), (220, 540, 250, 100), border_radius=9)
pygame.draw.rect(surface, (50, 200, 0), (220 - 10, 540 - 5, 270, 110), border_radius=9)
buttonNames(220 + 43, 540 + 40, "Start")
buttonNames(220 + 129, 540 + 40, "Play")
if mousePress[0]:
intro()
# run = False
pygame.display.update()
if __name__ == "__main__":
# main(3)
# intro()
# outro()
welcome()