-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser42_HRGclI3LZT_23.py
74 lines (61 loc) · 1.76 KB
/
user42_HRGclI3LZT_23.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
# template for "Stopwatch: The Game"
import simplegui
# define global variables
count = 0
wins = 0
tries = 0
timer_running = False
# define helper function format that converts time
# in tenths of seconds into formatted string A:BC.D
def format(t):
minutes = t//600
tens_seconds = ((t//10) %60)//10
seconds = int (((t / 10) % 10) % 60)
tenths = t % 10
return str(minutes) + ':' + str(tens_seconds) + str(seconds) + '.' + str(tenths)
# define event handlers for buttons; "Start", "Stop", "Reset"
def reset():
global wins
global tries
global count
global timer_running
timer_running = False
timer.stop()
count = 0
tries = 0
wins = 0
def start():
global tries
global timer_running
timer_running = True
timer.start()
tries += 1
def stop():
global wins
timer.stop()
global timer_running
if count % 10 == 0 and timer_running == True:
wins += 1
timer_running = False
# define event handler for timer with 0.1 sec interval
def tick():
global count
count += 1
# define draw handler
def draw(canvas):
global count
global wins
global tries
canvas.draw_text(format(count), (40, 120), 48, 'Red')
canvas.draw_text(str(wins) + ' / ' + str(tries), (150, 20), 18, 'Green')
# create frame
frame = simplegui.create_frame('Testing', 200, 200, 300)
# register event handlers
start_button = frame.add_button('Start',start)
stop_button = frame.add_button('Stop', stop)
reset_button = frame.add_button('Reset', reset)
timer = simplegui.create_timer(100,tick)
frame.set_draw_handler(draw)
# start frame
frame.start()
# Please remember to review the grading rubric