Merge branch 'story9' of https://eng-git.canterbury.ac.nz/seng302-2017/team-7 into story9
This commit is contained in:
@@ -25,12 +25,12 @@ public class Constants {
|
||||
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
||||
|
||||
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
|
||||
{new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET),
|
||||
new BoatInRace("Land Rover BAR", 500.0, Color.BLACK),
|
||||
new BoatInRace("SoftBank Team Japan", 400.0, Color.RED),
|
||||
new BoatInRace("Groupama Team France", 350.0, Color.ORANGE),
|
||||
new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN),
|
||||
new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN)};
|
||||
{new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET, "USA"),
|
||||
new BoatInRace("Land Rover BAR", 500.0, Color.BLACK, "BAR"),
|
||||
new BoatInRace("SoftBank Team Japan", 400.0, Color.RED, "JAP"),
|
||||
new BoatInRace("Groupama Team France", 350.0, Color.ORANGE, "FRN"),
|
||||
new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN, "ART"),
|
||||
new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN, "ENZ")};
|
||||
|
||||
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package seng302.Controllers;
|
||||
|
||||
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@@ -40,13 +39,15 @@ public class RaceController extends Controller{
|
||||
Label timer;
|
||||
|
||||
@FXML
|
||||
TableView boatInfoTable;
|
||||
TableView<BoatInRace> boatInfoTable;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatPlacingColumn;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatTeamColumn;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatMarkColumn;
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatSpeedColumn;
|
||||
|
||||
/**
|
||||
* updates the ResizableRaceCanvas (raceMap) with most recent data
|
||||
@@ -64,12 +65,13 @@ public class RaceController extends Controller{
|
||||
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
||||
* @param race Race to listen to.
|
||||
*/
|
||||
public void updateInfoTable(Race race) {
|
||||
boatInfoTable.getItems().clear();
|
||||
public void setInfoTable(Race race) {
|
||||
//boatInfoTable.getItems().clear();
|
||||
boatInfoTable.setItems(race.getStartingBoats());
|
||||
|
||||
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
||||
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
||||
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
||||
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
||||
@Override
|
||||
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
||||
|
||||
@@ -1,32 +1,45 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public class Boat {
|
||||
private String name;
|
||||
private StringProperty name;
|
||||
private double velocity;
|
||||
private StringProperty velocityProp;
|
||||
private String abbrev;
|
||||
|
||||
/**
|
||||
* Boat initialiser which keeps all of the information of the boat.
|
||||
* @param name Name of the Boat.
|
||||
* @param velocity Speed in m/s that the boat travels at.
|
||||
*/
|
||||
public Boat(String name, double velocity){
|
||||
public Boat(String name, double velocity, String abbrev){
|
||||
this.velocity = velocity;
|
||||
this.name = name;
|
||||
this.velocityProp = new SimpleStringProperty(String.valueOf(velocity));
|
||||
this.abbrev = abbrev;
|
||||
this.name = new SimpleStringProperty(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The name of the boat
|
||||
*/
|
||||
public String getName() {
|
||||
public StringProperty getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name.setValue(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return returns the speed of the boat.
|
||||
@@ -40,7 +53,13 @@ public class Boat {
|
||||
* @return The Name of the boat.
|
||||
*/
|
||||
public String toString(){
|
||||
return getName();
|
||||
return getName().getValue();
|
||||
}
|
||||
|
||||
public StringProperty getVelocityProp() {
|
||||
return velocityProp;
|
||||
}
|
||||
|
||||
public String getAbbrev() { return abbrev; }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package seng302.Model;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.GPSCoordinate;
|
||||
@@ -18,6 +20,7 @@ public class BoatInRace extends Boat {
|
||||
private long timeFinished;
|
||||
private Color colour;
|
||||
private boolean finished = false;
|
||||
private StringProperty currentLegName;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
@@ -25,9 +28,10 @@ public class BoatInRace extends Boat {
|
||||
* @param velocity Speed that the boat travels.
|
||||
* @param colour Colour the boat will be displayed as on the map
|
||||
*/
|
||||
public BoatInRace(String name, double velocity, Color colour) {
|
||||
super(name, velocity);
|
||||
public BoatInRace(String name, double velocity, Color colour, String abbrev) {
|
||||
super(name, velocity, abbrev);
|
||||
setColour(colour);
|
||||
currentLegName = new SimpleStringProperty("");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,6 +92,11 @@ public class BoatInRace extends Boat {
|
||||
*/
|
||||
public void setCurrentLeg(Leg currentLeg) {
|
||||
this.currentLeg = currentLeg;
|
||||
this.currentLegName.setValue(currentLeg.getName());
|
||||
}
|
||||
|
||||
public StringProperty getCurrentLegName(){
|
||||
return currentLegName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,8 +34,9 @@ public class Leg {
|
||||
* Construction Method
|
||||
* @param name Name of the Leg
|
||||
*/
|
||||
public Leg(String name) {
|
||||
public Leg(String name, int number) {
|
||||
this.name = name;
|
||||
this.legNumber = number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,8 @@ public abstract class Race implements Runnable {
|
||||
|
||||
|
||||
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||
private int PRERACE_TIME = 1000; //time in milliseconds to pause during pre-race
|
||||
private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race
|
||||
private boolean timerEnabled = true;
|
||||
|
||||
/**
|
||||
* Initailiser for Race
|
||||
@@ -35,7 +36,7 @@ public abstract class Race implements Runnable {
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish"));
|
||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@@ -52,12 +53,16 @@ public abstract class Race implements Runnable {
|
||||
* Runnable for the thread.
|
||||
*/
|
||||
public void run() {
|
||||
updateController();
|
||||
setControllerListeners();
|
||||
preRace();
|
||||
countdownTimer();
|
||||
if(timerEnabled) countdownTimer();
|
||||
simulateRace();
|
||||
}
|
||||
|
||||
public void disableTimer() {
|
||||
timerEnabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the state in waiting for the race starts.
|
||||
*/
|
||||
@@ -146,8 +151,8 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
controller.updateMap(startingBoats);
|
||||
updateTime(calcTimer());
|
||||
if(controller != null) controller.updateMap(startingBoats);
|
||||
if(timerEnabled) updateTime(calcTimer());
|
||||
try {
|
||||
timeLoopEnded = System.currentTimeMillis();
|
||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
||||
@@ -178,14 +183,15 @@ public abstract class Race implements Runnable {
|
||||
boat.setCurrentLeg(nextLeg);
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||
}
|
||||
FXCollections.sort(startingBoats, (a,b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update call for the controller.
|
||||
*/
|
||||
protected void updateController() {
|
||||
if(controller != null) controller.updateInfoTable(this);
|
||||
protected void setControllerListeners() {
|
||||
if(controller != null) controller.setInfoTable(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,6 +124,17 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display given name and speed of boat at a graph coordinate
|
||||
* @param name name of the boat
|
||||
* @param speed speed of the boat
|
||||
* @param coordinate coordinate the text appears
|
||||
*/
|
||||
public void displayText(String name, double speed, GraphCoordinate coordinate){
|
||||
String text = name + ", " + speed + " knots";
|
||||
gc.fillText(text, coordinate.getX()+20, coordinate.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the Race Map
|
||||
*/
|
||||
@@ -133,7 +144,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
double height = getHeight();
|
||||
|
||||
gc.clearRect(0, 0, width, height);
|
||||
System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
|
||||
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
|
||||
this.map = new RaceMap(32.278, -64.863, 32.320989, -64.821, (int)width, (int)height);
|
||||
|
||||
if (map == null){
|
||||
@@ -166,6 +177,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
if (boat != null) {
|
||||
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
||||
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
|
||||
<TableColumn fx:id="boatTeamColumn" prefWidth="50.0" text="Team" />
|
||||
<TableColumn fx:id="boatMarkColumn" prefWidth="50.0" text="Mark" />
|
||||
<TableColumn fx:id="boatSpeedColumn" prefWidth="75.0" text="Speed" />
|
||||
</columns>
|
||||
</TableView>
|
||||
</children>
|
||||
|
||||
Reference in New Issue
Block a user