Added a heartbeat value to the race.
-Heartbeat will display and update every 5 seconds. #story[778]
This commit is contained in:
@@ -2,6 +2,7 @@ package seng302.Model;
|
||||
|
||||
|
||||
import com.sun.org.apache.xpath.internal.SourceTree;
|
||||
import com.sun.xml.internal.bind.v2.TODO;
|
||||
import javafx.animation.AnimationTimer;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
@@ -32,7 +33,8 @@ public class Race implements Runnable {
|
||||
protected long totalTimeElapsed;
|
||||
private int lastFPS = 20;
|
||||
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 PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race
|
||||
@@ -68,9 +70,35 @@ public class Race implements Runnable {
|
||||
*/
|
||||
public void run() {
|
||||
initialiseBoats();
|
||||
outputHeartbeat();
|
||||
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.
|
||||
*/
|
||||
@@ -147,6 +175,10 @@ public class Race implements Runnable {
|
||||
if (boat != null && !boat.isFinished()) {
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
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) {
|
||||
if(boat != null) {
|
||||
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)
|
||||
boat.setPosition("-");
|
||||
}
|
||||
}
|
||||
System.out.println("=====");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user