-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtetris.py
44 lines (36 loc) · 994 Bytes
/
tetris.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
from Tkinter import *
import random
import time
from game import *
root = Tk()
root.geometry("400x500")
game = Tetris(root)
quit_button = Button(root, text="quit", command=root.quit)
quit_button.pack( side = TOP )
def down_callback():
if game.lost == True:
game.quit()
score = game.score
end_screen = Label(root, text="you lose. ("+str(score)+")")
end_screen.pack()
play_again_button = Button(root, text="play again?", command=play_again)
play_again_button.pack()
return
game.moveDown()
root.after(200, down_callback)
def force_down(e):
game.moveDown()
def left_callback(e):
game.moveLeft()
def right_callback(e):
game.moveRight()
def up_callback(e):
game.rotate()
def play_again():
Label(root, text="Too bad").pack()
root.bind("<Left>", left_callback)
root.bind("<Right>", right_callback)
root.bind("<Up>", up_callback)
root.bind("<Down>",force_down)
root.after(200, down_callback)
root.mainloop()