|
|
|
|
@ -23,7 +23,9 @@ public abstract class Race implements Runnable {
|
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
|
protected long totalTimeElapsed;
|
|
|
|
|
|
|
|
|
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
|
|
|
|
|
|
|
|
|
private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop
|
|
|
|
|
private int PRERACE_TIME = Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initailiser for Race
|
|
|
|
|
@ -52,6 +54,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
public void run() {
|
|
|
|
|
updateController();
|
|
|
|
|
preRace();
|
|
|
|
|
countdownTimer();
|
|
|
|
|
simulateRace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -72,6 +75,34 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void countdownTimer() {
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|
long startTime = currentTime + PRERACE_TIME;
|
|
|
|
|
long minutes;
|
|
|
|
|
long currentTimeInSeconds;
|
|
|
|
|
long remainingSeconds;
|
|
|
|
|
long hours;
|
|
|
|
|
long timeLeft;
|
|
|
|
|
long timeLoopEnded;
|
|
|
|
|
|
|
|
|
|
while (currentTime <= startTime) {
|
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
|
currentTimeInSeconds = timeLeft / 1000;
|
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
|
hours = minutes / 60;
|
|
|
|
|
minutes = minutes % 60;
|
|
|
|
|
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
|
|
|
|
|
try {
|
|
|
|
|
timeLoopEnded = System.currentTimeMillis();
|
|
|
|
|
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String calcTimer() {
|
|
|
|
|
long minutes;
|
|
|
|
|
long currentTimeInSeconds;
|
|
|
|
|
@ -82,7 +113,8 @@ public abstract class Race implements Runnable {
|
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
|
hours = minutes / 60;
|
|
|
|
|
return String.format("%02d:%02d:%02d", hours, minutes, remainingSeconds);
|
|
|
|
|
minutes = minutes % 60;
|
|
|
|
|
return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTime(String time){
|
|
|
|
|
|