Implemented DNF with random chance in Race

#story [17]
This commit is contained in:
cbt24
2017-03-29 11:18:04 +13:00
parent 6fe80ad52c
commit 99cb4bd526
+10
View File
@@ -11,6 +11,7 @@ import seng302.Controllers.RaceController;
import seng302.GPSCoordinate;
import java.util.ArrayList;
import java.util.Random;
/**
* Parent class for races
@@ -171,6 +172,11 @@ public abstract class Race implements Runnable {
Platform.runLater(() -> {controller.setFrames("FPS: " + fps);});
}
private boolean doNotFinish() {
Random rand = new Random();
return rand.nextInt(100) < 1;
}
/**
* 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.
@@ -240,6 +246,10 @@ public abstract class Race implements Runnable {
boatsFinished++;
boat.setFinished(true);
boat.setTimeFinished(timeElapsed);
} else if(doNotFinish()) {
boatsFinished++;
boat.setFinished(true);
boat.setCurrentLeg(new Leg("DNF",-1));
} else {
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);