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("=====");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals;
|
||||
* Created by esa46 on 16/03/17.
|
||||
*/
|
||||
public class ConstantVelocityRaceTest {
|
||||
|
||||
/*
|
||||
Marker START_MARKER = new Marker(new GPSCoordinate(0, 0));
|
||||
Marker END_MARKER = new Marker(new GPSCoordinate(10, 10));
|
||||
Leg START_LEG = new Leg("Start", START_MARKER, END_MARKER, 0);
|
||||
@@ -136,5 +136,5 @@ public class ConstantVelocityRaceTest {
|
||||
assertEquals(newPos.getLatitude(), calc.getDestinationGeographicPoint().getY(), 1e-8);
|
||||
assertEquals(newPos.getLongitude(), calc.getDestinationGeographicPoint().getX(), 1e-8);
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import static org.junit.Assert.assertTrue;
|
||||
* Created by esa46 on 15/03/17.
|
||||
*/
|
||||
public class RaceTest {
|
||||
|
||||
/*
|
||||
Leg START_LEG = new Leg("Start", new Marker(new GPSCoordinate(0, 0)), new Marker(new GPSCoordinate(1, 1)), 0);
|
||||
Leg FINISH_LEG = new Leg("Finish", new Marker(new GPSCoordinate(1, 1)), new Marker(new GPSCoordinate(2, 2)), 0);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class RaceTest {
|
||||
//assertTrue(System.currentTimeMillis() - timeStarted > 500);
|
||||
System.out.println(System.currentTimeMillis() - timeStarted);
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalerScalesVelocityCorrectly() {
|
||||
@@ -170,4 +170,5 @@ public class RaceTest {
|
||||
assertTrue(race.calcTimer().equals("Race clock: 02:40:39"));
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user