-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.rb
44 lines (37 loc) · 785 Bytes
/
timer.rb
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
class Timer
attr_reader :hours
attr_reader :minutes
attr_reader :seconds
attr_reader :state
def initialize
@hours = 0
@minutes = 0
@seconds = 0
@last_time = Gosu::milliseconds()
@state = :running
end
def stop
@state = :lost
end
def update_time
if @state == :running
if (Gosu::milliseconds - @last_time) / 1000 == 1
@seconds += 1
@last_time = Gosu::milliseconds()
end
if @seconds > 59
@seconds = 0
@minutes += 1
end
if @minutes > 59
@hours += 1
@minutes = 0
end
end
if @seconds < 10
time = "Time: " "0"[email protected]_s + ":" + "0" + @seconds.to_s
else
time = "Time: " "0"[email protected]_s + ":" + @seconds.to_s
end
end
end