-
Notifications
You must be signed in to change notification settings - Fork 14
/
clock.py
75 lines (55 loc) · 2.49 KB
/
clock.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
75
from time import process_time
class Clock:
"""set up a timer to record what is time to do"""
def __init__(self, st):
self.st = st
self.last_drop = process_time()
self.last_move = process_time()
self.last_rotate = process_time()
self.last_left_down = process_time()
self.last_right_down = process_time()
self.last_quick_drop = process_time()
self.last_stop = process_time()
self.last_should_stop = None # for detection of the stop at the very bottom
self.stop_detection_started = False
self.last_straight_drop = process_time()
def update_drop(self):
self.last_drop = process_time()
def update_move(self):
self.last_move = process_time()
def update_rotate(self):
self.last_rotate = process_time()
def update_left_down(self):
self.last_left_down = process_time()
def update_right_down(self):
self.last_right_down = process_time()
def update_quick_drop(self):
self.last_quick_drop = process_time()
def update_stop(self):
self.last_stop = process_time()
def update_should_stop(self, mode):
if mode is True and self.stop_detection_started is False:
self.last_should_stop = process_time()
self.stop_detection_started = True
elif mode is None:
self.stop_detection_started = False
def update_straight_drop(self):
self.last_straight_drop = process_time()
def is_time_to_drop(self):
return ((process_time() - self.last_drop) > self.st.time_drop)
def is_time_to_quick_drop(self):
return ((process_time() - self.last_quick_drop) > self.st.time_quick_drop) and\
((process_time() - self.last_stop) > self.st.time_before_drop)
def is_time_to_move(self):
return (process_time() - self.last_move) > self.st.time_move
def is_time_to_rotate(self):
return (process_time() - self.last_rotate) > self.st.time_rotate
def is_time_to_quick_left(self):
return (process_time() - self.last_left_down) > self.st.time_to_quick
def is_time_to_quick_right(self):
return (process_time() - self.last_right_down) > self.st.time_to_quick
def is_time_to_straight_drop(self):
return (process_time() - self.last_straight_drop) > self.st.time_to_straight_drop
def is_time_to_stop(self):
return self.stop_detection_started and\
((process_time() - self.last_should_stop) > self.st.time_stop)