Fixed countdown timer not scaling.
-Countdown timer now also uses an animation timer -Added scaling factor to countdown timer
This commit is contained in:
@@ -28,6 +28,24 @@
|
|||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
<version>1.9.5</version>
|
<version>1.9.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
<version>6.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class Race implements Runnable {
|
|||||||
protected int scaleFactor;
|
protected int scaleFactor;
|
||||||
|
|
||||||
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||||
protected int PRERACE_TIME = 5000; //time in milliseconds to pause during pre-race
|
protected int PRERACE_TIME = 15000; //time in milliseconds to pause during pre-race
|
||||||
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
private boolean timerEnabled = true; //boolean to determine if timer is ran
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +85,7 @@ public abstract class Race implements Runnable {
|
|||||||
setControllerListeners();
|
setControllerListeners();
|
||||||
initialiseBoats();
|
initialiseBoats();
|
||||||
if (timerEnabled) countdownTimer();
|
if (timerEnabled) countdownTimer();
|
||||||
simulateRace();
|
//simulateRace();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,21 +100,24 @@ public abstract class Race implements Runnable {
|
|||||||
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
||||||
*/
|
*/
|
||||||
protected void countdownTimer() {
|
protected void countdownTimer() {
|
||||||
|
new AnimationTimer() {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
long startTime = currentTime + PRERACE_TIME;
|
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
||||||
long minutes;
|
long minutes;
|
||||||
long currentTimeInSeconds;
|
long currentTimeInSeconds;
|
||||||
long remainingSeconds;
|
long remainingSeconds;
|
||||||
long hours;
|
long hours;
|
||||||
long timeLeft;
|
long timeLeft;
|
||||||
long timeLoopEnded;
|
|
||||||
|
|
||||||
while (currentTime <= startTime) {
|
@Override
|
||||||
|
public void handle(long arg0) {
|
||||||
timeLeft = startTime - currentTime;
|
timeLeft = startTime - currentTime;
|
||||||
if (timeLeft == 0 && controller != null) {
|
if (timeLeft <= 0 && controller != null) {
|
||||||
updateTime("Race is starting...");
|
updateTime("Race is starting...");
|
||||||
|
stop();
|
||||||
|
simulateRace();
|
||||||
} else {
|
} else {
|
||||||
currentTimeInSeconds = timeLeft / 1000;
|
currentTimeInSeconds = (timeLeft*scaleFactor) / 1000;
|
||||||
minutes = currentTimeInSeconds / 60;
|
minutes = currentTimeInSeconds / 60;
|
||||||
remainingSeconds = currentTimeInSeconds % 60;
|
remainingSeconds = currentTimeInSeconds % 60;
|
||||||
hours = minutes / 60;
|
hours = minutes / 60;
|
||||||
@@ -123,14 +126,9 @@ public abstract class Race implements Runnable {
|
|||||||
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
timeLoopEnded = System.currentTimeMillis();
|
|
||||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - currentTime));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
currentTime = System.currentTimeMillis();
|
currentTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user