|
|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package seng302.Model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javafx.application.Platform;
|
|
|
|
|
import javafx.beans.property.StringProperty;
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableArray;
|
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
@ -19,6 +21,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
protected ArrayList<Leg> legs;
|
|
|
|
|
protected RaceController controller;
|
|
|
|
|
protected int boatsFinished = 0;
|
|
|
|
|
protected long totalTimeElapsed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
|
|
|
|
@ -70,6 +73,26 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String calcTimer() {
|
|
|
|
|
long minutes;
|
|
|
|
|
long currentTimeInSeconds;
|
|
|
|
|
long remainingSeconds;
|
|
|
|
|
long hours;
|
|
|
|
|
|
|
|
|
|
currentTimeInSeconds = totalTimeElapsed / 1000;
|
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
|
hours = minutes/60;
|
|
|
|
|
return String.format("%02d:%02d:%02d", hours, minutes, remainingSeconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTime(String time){
|
|
|
|
|
|
|
|
|
|
Platform.runLater(() -> {controller.setTimer(time);});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starts the Race Simulation, playing the race start to finish with the timescale.
|
|
|
|
|
* This prints the boats participating, the order that the events occur in time order, and the respective information of the events.
|
|
|
|
|
@ -77,23 +100,15 @@ public abstract class Race implements Runnable {
|
|
|
|
|
private void simulateRace() {
|
|
|
|
|
|
|
|
|
|
long timeRaceStarted = System.currentTimeMillis();
|
|
|
|
|
long totalTimeElapsed;
|
|
|
|
|
|
|
|
|
|
long timeLoopStarted;
|
|
|
|
|
long timeLoopEnded;
|
|
|
|
|
long minutes;
|
|
|
|
|
long currentTimeInSeconds;
|
|
|
|
|
long remainingSeconds;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (boatsFinished < startingBoats.size()) {
|
|
|
|
|
timeLoopStarted = System.currentTimeMillis();
|
|
|
|
|
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
|
|
|
|
long currentTime = System.currentTimeMillis() - timeRaceStarted;
|
|
|
|
|
currentTimeInSeconds = currentTime / 1000;
|
|
|
|
|
minutes = currentTimeInSeconds / 60;
|
|
|
|
|
remainingSeconds = currentTimeInSeconds % 60;
|
|
|
|
|
System.out.println(minutes + ":" + remainingSeconds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (BoatInRace boat : startingBoats) {
|
|
|
|
|
if (boat != null && !boat.isFinished()) {
|
|
|
|
|
@ -103,6 +118,7 @@ public abstract class Race implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller.updateMap(startingBoats);
|
|
|
|
|
updateTime(calcTimer());
|
|
|
|
|
try {
|
|
|
|
|
timeLoopEnded = System.currentTimeMillis();
|
|
|
|
|
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
|
|
|
|
|