Fixed DNF position handling

- DNF position is now "-"
- If boat DNFs during leg, other boats' rankings are updated to remain accurate
#story[15]
main
cbt24 9 years ago
parent c31ea51068
commit 2d74cdc5dc

@ -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
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());
boat.setPosition(startingBoats.indexOf(boat));
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("-");
}
}
}

Loading…
Cancel
Save