-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
74 lines (65 loc) · 2.11 KB
/
gui.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
__author__ = 'Robin'
"""
Graphical interface for pyTetris
"""
from Setup import *
import random
clock = pygame.time.Clock()
t_1 = 1
t_2 = 1
# Start the game with a random tetramino
controller.exec_command(random.choice(TETRAMINOS))
while not model.game_mode == 'game over':
clock.tick(RATE)
# commands to be executed every 1 sec
if not t_1 % RATE:
# check if the active tetramino has settled, create a new one (random)
if np.all(model.active_grid == '.'):
controller.exec_command(random.choice(TETRAMINOS))
draw_grid()
t_1 = 0
t_1 += 1
# commands to be executed at the pace set by the level; every level, game
# is one RATE faster
if not t_2 % (max(RATE - model.level,1)):
controller.exec_command('v') # move down active tetramino one step
controller.exec_command('s') # check for lines to be cleared
draw_grid()
t_2 = 0
t_2 += 1
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_LEFT:
controller.exec_command('<')
draw_grid()
elif event.key == K_RIGHT:
controller.exec_command('>')
draw_grid()
elif event.key == K_DOWN:
controller.exec_command('v')
draw_grid()
elif event.key == K_x:
controller.exec_command('V')
draw_grid()
elif event.key == K_SPACE:
controller.exec_command('!')
elif event.key == K_a:
controller.exec_command('(')
draw_grid()
elif event.key == K_d:
controller.exec_command(')')
draw_grid()
elif event.key == K_p:
draw_grid()
elif event.key == K_ESCAPE:
sys.exit()
pygame.display.update()
# Game Over! Wait for user to quit.
draw_score(0,0)
while True:
clock.tick(RATE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()