|
|
|
@ -2,6 +2,7 @@ package seng302.Model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
|
|
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
|
|
|
|
|
|
|
import com.sun.xml.internal.bind.v2.TODO;
|
|
|
|
import javafx.animation.AnimationTimer;
|
|
|
|
import javafx.animation.AnimationTimer;
|
|
|
|
|
|
|
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
@ -32,7 +33,8 @@ public class Race implements Runnable {
|
|
|
|
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
|
|
|
|
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
|
|
|
|
|
|
|
protected int heartbeat = 0;
|
|
|
|
|
|
|
|
protected boolean raceFinish = false;
|
|
|
|
protected int scaleFactor;
|
|
|
|
protected int scaleFactor;
|
|
|
|
|
|
|
|
|
|
|
|
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
|
|
|
protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
|
|
|
@ -68,9 +70,35 @@ public class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
initialiseBoats();
|
|
|
|
initialiseBoats();
|
|
|
|
|
|
|
|
outputHeartbeat();
|
|
|
|
countdownTimer();
|
|
|
|
countdownTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void outputHeartbeat() {
|
|
|
|
|
|
|
|
AnimationTimer heartbeatTimer = new AnimationTimer() {
|
|
|
|
|
|
|
|
long currentHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
long endHeartbeatTime = System.currentTimeMillis() + 5000;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void handle(long now) {
|
|
|
|
|
|
|
|
if (currentHeartbeatTime >= endHeartbeatTime) {
|
|
|
|
|
|
|
|
System.out.println("-------");
|
|
|
|
|
|
|
|
System.out.println("Heartbeat value: " + heartbeat);
|
|
|
|
|
|
|
|
System.out.println("-------");
|
|
|
|
|
|
|
|
endHeartbeatTime = System.currentTimeMillis() + 5000;
|
|
|
|
|
|
|
|
heartbeat++;
|
|
|
|
|
|
|
|
//TODO: Send heartbeat value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if (raceFinish) {
|
|
|
|
|
|
|
|
System.out.println("Heartbeat stopping");
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentHeartbeatTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
heartbeatTimer.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
|
|
|
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -147,6 +175,10 @@ public class Race implements Runnable {
|
|
|
|
if (boat != null && !boat.isFinished()) {
|
|
|
|
if (boat != null && !boat.isFinished()) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
System.out.println("Race is over");
|
|
|
|
|
|
|
|
//raceFinish = true;
|
|
|
|
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -164,11 +196,12 @@ public 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());
|
|
|
|
System.out.println(boat.toString() + " " + 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("-");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("=====");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|