-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameClock.java
More file actions
42 lines (38 loc) · 716 Bytes
/
GameClock.java
File metadata and controls
42 lines (38 loc) · 716 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
public class GameClock
{
private long millisLeft;
private long startTime;
private boolean timerTicking;
public GameClock(long seconds)
{
millisLeft = seconds * 1000;
timerTicking = false;
}
public void start()
{
if(!timerTicking)
{
startTime = System.currentTimeMillis();
timerTicking = true;
}
}
public void pause()
{
if(timerTicking)
{
long elapsed = System.currentTimeMillis() - startTime;
millisLeft -= elapsed;
timerTicking = false;
}
}
public long millisRemaining()
{
if(timerTicking)
{
long elapsed = System.currentTimeMillis() - startTime;
return millisLeft - elapsed;
}
else
return millisLeft;
}
}