|
|
|
@ -118,15 +118,18 @@ public abstract class Race implements Runnable {
|
|
|
|
long timeLoopEnded;
|
|
|
|
long timeLoopEnded;
|
|
|
|
|
|
|
|
|
|
|
|
while (currentTime <= startTime) {
|
|
|
|
while (currentTime <= startTime) {
|
|
|
|
//if (controller != null) controller.updateMap(startingBoats);
|
|
|
|
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
timeLeft = startTime - currentTime;
|
|
|
|
|
|
|
|
if (timeLeft == 0 && controller != null) {
|
|
|
|
|
|
|
|
updateTime("Race is starting...");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
currentTimeInSeconds = timeLeft / 1000;
|
|
|
|
currentTimeInSeconds = timeLeft / 1000;
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
hours = minutes / 60;
|
|
|
|
hours = minutes / 60;
|
|
|
|
minutes = minutes % 60;
|
|
|
|
minutes = minutes % 60;
|
|
|
|
if (controller != null) {
|
|
|
|
if (controller != null) {
|
|
|
|
updateTime(String.format("Time until race starts: %02d:%02d:%02d", hours, minutes, remainingSeconds));
|
|
|
|
updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
timeLoopEnded = System.currentTimeMillis();
|
|
|
|
timeLoopEnded = System.currentTimeMillis();
|
|
|
|
@ -162,6 +165,16 @@ public abstract class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected void updateTime(String time){
|
|
|
|
protected void updateTime(String time){
|
|
|
|
Platform.runLater(() -> {controller.setTimer(time);});
|
|
|
|
Platform.runLater(() -> {controller.setTimer(time);});
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
* Updates the GUI race clock
|
|
|
|
|
|
|
|
* @param time
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected void updateTime(String time) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Platform.runLater(() -> {
|
|
|
|
|
|
|
|
controller.setTimer(time);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
>>>>>>> Temporary merge branch 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -183,6 +196,8 @@ public abstract class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void simulateRace() {
|
|
|
|
private void simulateRace() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.setProperty("javafx.animation.fullspeed", "true");
|
|
|
|
|
|
|
|
|
|
|
|
new AnimationTimer() {
|
|
|
|
new AnimationTimer() {
|
|
|
|
|
|
|
|
|
|
|
|
long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
|
|
|
long timeRaceStarted = System.currentTimeMillis(); //start time of loop
|
|
|
|
@ -242,7 +257,6 @@ public abstract class Race implements Runnable {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
|
|
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
|
|
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
|
|
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
|
|
|
// updateController();
|
|
|
|
|
|
|
|
//boat has passed onto new leg
|
|
|
|
//boat has passed onto new leg
|
|
|
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
|
|
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
|
|
|
//boat has finished
|
|
|
|
//boat has finished
|
|
|
|
@ -254,12 +268,16 @@ public abstract class Race implements Runnable {
|
|
|
|
boat.setFinished(true);
|
|
|
|
boat.setFinished(true);
|
|
|
|
boat.setCurrentLeg(new Leg("DNF",-1));
|
|
|
|
boat.setCurrentLeg(new Leg("DNF",-1));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//Calculate how much the boat overshot the marker by
|
|
|
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
|
|
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
|
|
|
|
|
|
|
//Move boat on to next leg
|
|
|
|
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
|
|
|
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
|
|
|
|
|
|
|
|
|
|
|
boat.setCurrentLeg(nextLeg);
|
|
|
|
boat.setCurrentLeg(nextLeg);
|
|
|
|
|
|
|
|
//Add overshoot distance into the distance travelled for the next leg
|
|
|
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
|
|
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Update the boat display table in the GUI to reflect the leg change
|
|
|
|
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
|
|
|
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -282,9 +300,9 @@ public abstract class Race implements Runnable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This function is a function that generates the Race and populates the events list.
|
|
|
|
* Updates the boat's gps coordinates depending on time elapsed
|
|
|
|
* Is automatically called by the initialiser function, so that simulateRace() does not return an empty race.
|
|
|
|
* @param boat
|
|
|
|
* @see Race#simulateRace()
|
|
|
|
* @param millisecondsElapsed
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected abstract void updatePosition(BoatInRace boat, int millisecondsElapsed);
|
|
|
|
protected abstract void updatePosition(BoatInRace boat, int millisecondsElapsed);
|
|
|
|
|
|
|
|
|
|
|
|
|