|
|
|
@ -25,6 +25,7 @@ public abstract class Race implements Runnable {
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
protected long totalTimeElapsed;
|
|
|
|
protected long totalTimeElapsed;
|
|
|
|
private int lastFPS = 20;
|
|
|
|
private int lastFPS = 20;
|
|
|
|
|
|
|
|
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
|
|
|
|
|
|
|
|
|
|
|
protected int scaleFactor;
|
|
|
|
protected int scaleFactor;
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,7 +68,7 @@ public abstract class Race implements Runnable {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Checks the position of the boat, this updates the boats current position.
|
|
|
|
* Checks the position of the boat, this updates the boats current position.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param boat Boat that the postion is to be updated for.
|
|
|
|
* @param boat Boat that the position is to be updated for.
|
|
|
|
* @param timeElapsed Time that has elapse since the start of the the race.
|
|
|
|
* @param timeElapsed Time that has elapse since the start of the the race.
|
|
|
|
* @see BoatInRace
|
|
|
|
* @see BoatInRace
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -86,16 +87,14 @@ public abstract class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
initialiseBoats();
|
|
|
|
initialiseBoats();
|
|
|
|
System.out.println("Running race");
|
|
|
|
countdownTimer();
|
|
|
|
simulateRace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
System.out.println("Running countdown timer");
|
|
|
|
AnimationTimer timer = new AnimationTimer() {
|
|
|
|
new AnimationTimer() {
|
|
|
|
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
|
|
|
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
|
|
|
|
long minutes;
|
|
|
|
long minutes;
|
|
|
|
@ -106,9 +105,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void handle(long arg0) {
|
|
|
|
public void handle(long arg0) {
|
|
|
|
System.out.println("Starting timer");
|
|
|
|
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
System.out.println(timeLeft);
|
|
|
|
|
|
|
|
if (timeLeft <= 0) {
|
|
|
|
if (timeLeft <= 0) {
|
|
|
|
stop();
|
|
|
|
stop();
|
|
|
|
simulateRace();
|
|
|
|
simulateRace();
|
|
|
|
@ -121,8 +118,8 @@ public abstract class Race implements Runnable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
currentTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.start();
|
|
|
|
};
|
|
|
|
System.out.println("Running countdown timer");
|
|
|
|
timer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -159,30 +156,19 @@ public abstract class Race implements Runnable {
|
|
|
|
new AnimationTimer() {
|
|
|
|
new AnimationTimer() {
|
|
|
|
|
|
|
|
|
|
|
|
long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
|
|
|
long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
|
|
|
int fps = 0; //init fps value
|
|
|
|
|
|
|
|
long timeCurrent = System.currentTimeMillis(); //current time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void handle(long arg0) {
|
|
|
|
public void handle(long arg0) {
|
|
|
|
System.out.println();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (boatsFinished < startingBoats.size()) {
|
|
|
|
if (boatsFinished < startingBoats.size()) {
|
|
|
|
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
|
|
|
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
|
|
|
|
|
|
|
|
|
|
|
for (BoatInRace boat : startingBoats) {
|
|
|
|
for (BoatInRace boat : startingBoats) {
|
|
|
|
if (boat != null && !boat.isFinished()) {
|
|
|
|
if (boat != null && !boat.isFinished()) {
|
|
|
|
boat.addTrackPoint(boat.getCurrentPosition());
|
|
|
|
|
|
|
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
|
|
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
|
|
|
checkPosition(boat, totalTimeElapsed);
|
|
|
|
checkPosition(boat, totalTimeElapsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fps++;
|
|
|
|
|
|
|
|
if ((System.currentTimeMillis() - timeCurrent) > 1000) {
|
|
|
|
|
|
|
|
lastFPS = fps;
|
|
|
|
|
|
|
|
fps = 0;
|
|
|
|
|
|
|
|
timeCurrent = System.currentTimeMillis();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -197,6 +183,7 @@ public abstract class Race implements Runnable {
|
|
|
|
for(BoatInRace boat: startingBoats) {
|
|
|
|
for(BoatInRace boat: startingBoats) {
|
|
|
|
if(boat != null) {
|
|
|
|
if(boat != null) {
|
|
|
|
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
|
|
|
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
|
|
|
|
|
|
|
System.out.println(boat.getName() + boat.getPosition());
|
|
|
|
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
|
|
|
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
|
|
|
boat.setPosition("-");
|
|
|
|
boat.setPosition("-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|