-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerDisplay.java
More file actions
95 lines (86 loc) · 1.91 KB
/
Copy pathTimerDisplay.java
File metadata and controls
95 lines (86 loc) · 1.91 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* This class is responsible for storing the game timer values for bonus, total and current times. It also handles a toString conversion from seconds to HH:MM:SS format
*
*/
public class TimerDisplay {
//Class constants
private final int BONUSTIME = 40;
private final int EXTRATIME = 30;
//Class variables
private int seconds = 600;
private int total = 600;
private int bonus = 40;
/**
* Constructor.
*
* @param startTime Initial Game time
*/
public TimerDisplay(int startTime){
seconds = startTime;
bonus = BONUSTIME;
total = seconds;
}
/**
* Increment the seconds value
*/
public void incrementSecond() {
seconds--;
if(bonus > 0){
bonus--;
}
}
/**
* Add time to current, total and bonus time values.
*/
public void addTime(){
seconds = seconds + EXTRATIME + bonus;
total = total + EXTRATIME + bonus;
bonus = BONUSTIME;
}
/**
* Get the seconds field.
*
* @return int seconds
*/
public int getSeconds() {
return seconds;
}
/**
* Get the time in hh:mm:ss format.
*
* @return time String
*/
public String getTotal() {
return hourMinSecFormat(total);
}
/**
* Get time.
*
* @return time String
*/
public String getTime(){
return hourMinSecFormat(this.seconds);
}
/**
* Get the bonus time.
*
* @return time String
*/
public String getBonus(){
return hourMinSecFormat(this.bonus);
}
/**
* Format the time into HH:MM:SS.
*
* @param seconds time as int
* @return time String
*/
private String hourMinSecFormat(int seconds) {
//Code from: http://stackoverflow.com/questions/6118922/convert-seconds-value-to-hours-minutes-seconds
//By: Bigtoes
int hours = seconds / 3600;
int minutes = (seconds % 3600) / 60;
seconds = seconds % 60;
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
}
}