Fixed boat position calculation
- Decoupled 'place' column data from position in table - Set position in race after first mark passed #story[15]
This commit is contained in:
@@ -76,12 +76,7 @@ public class RaceController extends Controller {
|
|||||||
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||||
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
||||||
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||||
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||||
@Override
|
|
||||||
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
|
||||||
return new ReadOnlyObjectWrapper(boatInfoTable.getItems().indexOf(table.getValue()) + 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.beans.property.IntegerProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -24,6 +25,7 @@ public class BoatInRace extends Boat {
|
|||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
private StringProperty currentLegName;
|
private StringProperty currentLegName;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
|
private StringProperty position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -36,6 +38,7 @@ public class BoatInRace extends Boat {
|
|||||||
super(name, velocity, abbrev);
|
super(name, velocity, abbrev);
|
||||||
setColour(colour);
|
setColour(colour);
|
||||||
currentLegName = new SimpleStringProperty("");
|
currentLegName = new SimpleStringProperty("");
|
||||||
|
position = new SimpleStringProperty("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -235,4 +238,16 @@ public class BoatInRace extends Boat {
|
|||||||
public void setStarted(boolean started) {
|
public void setStarted(boolean started) {
|
||||||
this.started = started;
|
this.started = started;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPosition() {
|
||||||
|
return position.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty positionProperty() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(int position) {
|
||||||
|
this.position.set(Integer.toString(position + 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,6 +263,7 @@ public abstract class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
//Update the boat display table in the GUI to reflect the leg change
|
//Update the boat display table in the GUI to reflect the leg change
|
||||||
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
FXCollections.sort(startingBoats, (a, b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||||
|
boat.setPosition(startingBoats.indexOf(boat));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user