-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (43 loc) · 1.49 KB
/
main.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
import constants
from game import TetrisGame
if __name__ == '__main__':
print(
'\nMoves: ',
'\n\ta = move piece left + down,'
'\n\tb = move piece right + down,',
'\n\tw = rotate piece counter clockwise + down',
'\n\ts = rotate piece clockwise + down'
)
game = TetrisGame(width=20, height=20)
game.new_piece()
game.place_piece()
game.draw_area()
while game.state == 'play!':
print('Select your move!')
move = input()
while move not in constants.POSSIBLE_MOVES:
print('Incorrect move, try to select again!')
move = input()
if game.avaliable_moves():
if move == 'a':
game.move_piece(side='left')
elif move == 'd':
game.move_piece(side='right')
elif move == 'w':
game.move_piece(side='counter_clockwise')
elif move == 's':
game.move_piece(side='clockwise')
else:
game.block_piece()
# Remove last piece from the area
game.clear_area()
# Place piece with its new position
game.place_piece()
# Print game board in the nice format
game.draw_area()
if game.state == 'gameover':
print(
'\n\tGame has finished!'
'\n(lack of avaliable moves to perform / piece has tried to spawn at the position of the past one)'
'\nHave a nice day!'
)