Fixed DNF position handling
- DNF position is now "-" - If boat DNFs during leg, other boats' rankings are updated to remain accurate #story[15]
This commit is contained in:
@@ -217,7 +217,7 @@ public class BoatInRace extends Boat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if boat has finished, fals eif not
|
||||
* @return true if boat has finished, false if not
|
||||
*/
|
||||
public boolean isFinished() {
|
||||
return this.finished;
|
||||
@@ -248,7 +248,7 @@ public class BoatInRace extends Boat {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position.set(Integer.toString(position + 1));
|
||||
public void setPosition(String position) {
|
||||
this.position.set(position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public abstract class Race implements Runnable {
|
||||
|
||||
private boolean doNotFinish() {
|
||||
Random rand = new Random();
|
||||
return rand.nextInt(100) < 1;
|
||||
return rand.nextInt(4) < 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,8 +262,21 @@ public abstract class Race implements Runnable {
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||
}
|
||||
//Update the boat display table in the GUI to reflect the leg change
|
||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||
boat.setPosition(startingBoats.indexOf(boat));
|
||||
updatePositions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update position of boats in race, no position if on starting leg or DNF.
|
||||
*/
|
||||
private void updatePositions() {
|
||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||
for(BoatInRace boat: startingBoats) {
|
||||
if(boat != null) {
|
||||
boat.setPosition(Integer.toString(startingBoats.indexOf(boat) + 1));
|
||||
if (boat.getCurrentLeg().getName().equals("DNF") || boat.getCurrentLeg().getLegNumber() == 0)
|
||||
boat.setPosition("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user