-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
44 lines (35 loc) · 796 Bytes
/
timer.py
File metadata and controls
44 lines (35 loc) · 796 Bytes
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
#Marios
import turtle
import time
wn = turtle.Screen()
wn.title("Game Timer Demo")
wn.bgcolor("black")
bob = turtle.Turtle()
bob.speed(0)
bob.color("yellow")
bob.shape("triangle")
bob.penup()
is_paused = False
def toggle_pause():
global is_paused
if is_paused == True:
is_paused = False
else:
is_paused = True
wn.listen()
wn.onkeypress(toggle_pause, "p")
time_limit = 10
start_time = time.time()
while True:
if not is_paused:
bob.fd(1)
bob.lt(1)
# Timer
elapsed_time = time.time() - start_time
print(time_limit - int(elapsed_time))
if elapsed_time > time_limit:
print("GAME OVER")
exit()
else:
start_time = time.time() - elapsed_time
wn.update()