Fixes to get race running
- Had an incorrect if else statement that was preventing race from running #story[778]
This commit is contained in:
@@ -43,7 +43,7 @@ public class Event {
|
|||||||
System.out.println("Sending Boat");
|
System.out.println("Sending Boat");
|
||||||
sendBoatData();
|
sendBoatData();
|
||||||
|
|
||||||
Race newRace = new Race(raceDataSource, 3, mockOutput);
|
Race newRace = new Race(raceDataSource, 15, mockOutput);
|
||||||
new Thread((newRace)).start();
|
new Thread((newRace)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,46 +112,40 @@ public class Race implements Runnable {
|
|||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
long startTime = currentTime + (PRERACE_TIME / scaleFactor);
|
long startTime = currentTime + (PRERACE_TIME / scaleFactor);
|
||||||
long minutes;
|
long minutes;
|
||||||
long currentTimeInSeconds;
|
|
||||||
long remainingSeconds;
|
|
||||||
long hours;
|
long hours;
|
||||||
long timeLeft;
|
long timeLeft;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long arg0) {
|
public void handle(long arg0) {
|
||||||
timeLeft = startTime - currentTime;
|
timeLeft = startTime - currentTime;
|
||||||
|
System.out.println(timeLeft);
|
||||||
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<>();
|
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<>();
|
||||||
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
|
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getScaledVelocity());
|
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), 0);
|
||||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||||
|
|
||||||
|
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
|
||||||
|
|
||||||
if (timeLeft <= 60000/scaleFactor) {
|
|
||||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
||||||
mockOutput.parseRaceStatus(raceStatus);
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
}
|
}
|
||||||
else if (timeLeft <= 0) {
|
else if (timeLeft <= 0) {
|
||||||
countdownFinish = true;
|
countdownFinish = true;
|
||||||
stop();
|
|
||||||
if (runRace) {
|
if (runRace) {
|
||||||
simulateRace();
|
simulateRace();
|
||||||
}
|
}
|
||||||
} else {
|
System.out.println("Stopping");
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
else {
|
||||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
||||||
mockOutput.parseRaceStatus(raceStatus);
|
mockOutput.parseRaceStatus(raceStatus);
|
||||||
currentTimeInSeconds = (timeLeft * scaleFactor) / 1000;
|
|
||||||
minutes = currentTimeInSeconds / 60;
|
|
||||||
remainingSeconds = currentTimeInSeconds % 60;
|
|
||||||
hours = minutes / 60;
|
|
||||||
minutes = minutes % 60;
|
|
||||||
}
|
}
|
||||||
currentTime = System.currentTimeMillis();
|
currentTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user