Created finish view to see when a race finishes.
-Implemented FinishController -Fixed mock not sending Finish race status. #Story[782]
This commit is contained in:
@@ -31,7 +31,7 @@ public class Race implements Runnable {
|
||||
protected List<Leg> legs;
|
||||
protected int boatsFinished = 0;
|
||||
protected long totalTimeElapsed;
|
||||
protected int scaleFactor;
|
||||
protected int scaleFactor=25;
|
||||
protected int PRERACE_TIME = 180000; //time in milliseconds to pause during pre-race. At the moment, 3 minutes
|
||||
protected boolean countdownFinish = false;
|
||||
protected boolean runRace = true;
|
||||
@@ -40,6 +40,7 @@ public class Race implements Runnable {
|
||||
private int dnfChance = 0; //percentage chance a boat fails at each checkpoint
|
||||
private MockOutput mockOutput;
|
||||
private static int boatOffset = 0;
|
||||
private int finished = 0;
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public class Race implements Runnable {
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
this.raceId = raceID;
|
||||
this.scaleFactor = scaleFactor;
|
||||
this.scaleFactor = 50;
|
||||
this.mockOutput = mockOutput;
|
||||
|
||||
|
||||
@@ -131,7 +132,6 @@ public class Race implements Runnable {
|
||||
boatOffset = (boatOffset + 1) % (startingBoats.size());
|
||||
|
||||
if (timeLeft <= 60000/scaleFactor && timeLeft > 0) {
|
||||
System.out.println("Race status 2");
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 2, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
@@ -143,7 +143,6 @@ public class Race implements Runnable {
|
||||
stop();
|
||||
}
|
||||
else {
|
||||
System.out.println("Race status 1");
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 1, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
@@ -178,7 +177,7 @@ public class Race implements Runnable {
|
||||
//Update the total elapsed time.
|
||||
totalTimeElapsed = currentTime - timeRaceStarted;
|
||||
ArrayList<BoatStatusMessage> boatStatusMessages = new ArrayList<BoatStatusMessage>();
|
||||
|
||||
finished = 0;
|
||||
//For each boat, we update it's position, and generate a BoatLocationMessage.
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
Boat boat = startingBoats.get((i + boatOffset) % startingBoats.size());
|
||||
@@ -188,9 +187,19 @@ public class Race implements Runnable {
|
||||
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
if (boat.getTimeFinished() > 0) {
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(), BoatStatus.FINISHED, boat.getCurrentLeg().getLegNumber()));
|
||||
finished++;
|
||||
} else {
|
||||
mockOutput.parseBoatLocation(boat.getSourceID(), boat.getCurrentPosition().getLatitude(), boat.getCurrentPosition().getLongitude(), boat.getHeading(), boat.getVelocity());
|
||||
boatStatusMessages.add(new BoatStatusMessage(boat.getSourceID(),
|
||||
boat.getCurrentLeg().getLegNumber() >= 0 ? BoatStatus.RACING : BoatStatus.DNF, boat.getCurrentLeg().getLegNumber()));
|
||||
}
|
||||
if (startingBoats.size()==finished){
|
||||
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, 2, boatStatusMessages);
|
||||
mockOutput.parseRaceStatus(raceStatus);
|
||||
}
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user