|
|
|
|
@ -25,7 +25,8 @@ public abstract class Race implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
|
|
|
|
private int PRERACE_TIME = 1000; //time in milliseconds to pause during pre-race
|
|
|
|
|
private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
|
|
|
|
|
private boolean timerEnabled = true;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initailiser for Race
|
|
|
|
|
@ -35,7 +36,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
|
|
|
|
this.startingBoats = FXCollections.observableArrayList(boats);
|
|
|
|
|
this.legs = legs;
|
|
|
|
|
this.legs.add(new Leg("Finish"));
|
|
|
|
|
this.legs.add(new Leg("Finish", this.legs.size()));
|
|
|
|
|
this.controller = controller;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -52,12 +53,16 @@ public abstract class Race implements Runnable {
|
|
|
|
|
* Runnable for the thread.
|
|
|
|
|
*/
|
|
|
|
|
public void run() {
|
|
|
|
|
updateController();
|
|
|
|
|
setControllerListeners();
|
|
|
|
|
preRace();
|
|
|
|
|
countdownTimer();
|
|
|
|
|
if(timerEnabled) countdownTimer();
|
|
|
|
|
simulateRace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void disableTimer() {
|
|
|
|
|
timerEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up the state in waiting for the race starts.
|
|
|
|
|
*/
|
|
|
|
|
@ -146,8 +151,8 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller.updateMap(startingBoats);
|
|
|
|
|
updateTime(calcTimer());
|
|
|
|
|
if(controller != null) controller.updateMap(startingBoats);
|
|
|
|
|
if(timerEnabled) updateTime(calcTimer());
|
|
|
|
|
try {
|
|
|
|
|
timeLoopEnded = System.currentTimeMillis();
|
|
|
|
|
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
|
|
|
|
@ -178,14 +183,15 @@ public abstract class Race implements Runnable {
|
|
|
|
|
boat.setCurrentLeg(nextLeg);
|
|
|
|
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
|
|
|
|
}
|
|
|
|
|
FXCollections.sort(startingBoats, (a,b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update call for the controller.
|
|
|
|
|
*/
|
|
|
|
|
protected void updateController() {
|
|
|
|
|
if(controller != null) controller.updateInfoTable(this);
|
|
|
|
|
protected void setControllerListeners() {
|
|
|
|
|
if(controller != null) controller.setInfoTable(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|