Erika Savell 9 years ago
commit 74a9b1499c

@ -25,12 +25,12 @@ public class Constants {
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260); public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[] public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
{new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET), {new BoatInRace("Oracle Team USA", 300.0, Color.BLUEVIOLET, "USA"),
new BoatInRace("Land Rover BAR", 500.0, Color.BLACK), new BoatInRace("Land Rover BAR", 500.0, Color.BLACK, "BAR"),
new BoatInRace("SoftBank Team Japan", 400.0, Color.RED), new BoatInRace("SoftBank Team Japan", 400.0, Color.RED, "JAP"),
new BoatInRace("Groupama Team France", 350.0, Color.ORANGE), new BoatInRace("Groupama Team France", 350.0, Color.ORANGE, "FRN"),
new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN), new BoatInRace("Artemis Racing", 440.0, Color.DARKOLIVEGREEN, "ART"),
new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN)}; new BoatInRace("Emirates Team New Zealand", 620, Color.LIMEGREEN, "ENZ")};
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new ) //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.ReadOnlyObjectWrapper;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@ -40,13 +39,15 @@ public class RaceController extends Controller{
Label timer; Label timer;
@FXML @FXML
TableView boatInfoTable; TableView<BoatInRace> boatInfoTable;
@FXML @FXML
TableColumn<BoatInRace, String> boatPlacingColumn; TableColumn<BoatInRace, String> boatPlacingColumn;
@FXML @FXML
TableColumn<BoatInRace, String> boatTeamColumn; TableColumn<BoatInRace, String> boatTeamColumn;
@FXML @FXML
TableColumn<BoatInRace, String> boatMarkColumn; TableColumn<BoatInRace, String> boatMarkColumn;
@FXML
TableColumn<BoatInRace, String> boatSpeedColumn;
/** /**
* updates the ResizableRaceCanvas (raceMap) with most recent data * 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. * Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
* @param race Race to listen to. * @param race Race to listen to.
*/ */
public void updateInfoTable(Race race) { public void setInfoTable(Race race) {
boatInfoTable.getItems().clear(); //boatInfoTable.getItems().clear();
boatInfoTable.setItems(race.getStartingBoats()); boatInfoTable.setItems(race.getStartingBoats());
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name")); boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg")); boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() { boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
@Override @Override
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) { public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {

@ -1,32 +1,45 @@
package seng302.Model; 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; import java.util.ArrayList;
/** /**
* Created by fwy13 on 3/03/17. * Created by fwy13 on 3/03/17.
*/ */
public class Boat { public class Boat {
private String name; private StringProperty name;
private double velocity; private double velocity;
private StringProperty velocityProp;
private String abbrev;
/** /**
* Boat initialiser which keeps all of the information of the boat. * Boat initialiser which keeps all of the information of the boat.
* @param name Name of the Boat. * @param name Name of the Boat.
* @param velocity Speed in m/s that the boat travels at. * @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.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 * @return The name of the boat
*/ */
public String getName() { public StringProperty getName() {
return name; return name;
} }
public void setName(String name) {
this.name.setValue(name);
}
/** /**
* *
* @return returns the speed of the boat. * @return returns the speed of the boat.
@ -40,7 +53,13 @@ public class Boat {
* @return The Name of the boat. * @return The Name of the boat.
*/ */
public String toString(){ 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; package seng302.Model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
@ -18,6 +20,7 @@ public class BoatInRace extends Boat {
private long timeFinished; private long timeFinished;
private Color colour; private Color colour;
private boolean finished = false; private boolean finished = false;
private StringProperty currentLegName;
/** /**
* Constructor method. * Constructor method.
@ -25,9 +28,10 @@ public class BoatInRace extends Boat {
* @param velocity Speed that the boat travels. * @param velocity Speed that the boat travels.
* @param colour Colour the boat will be displayed as on the map * @param colour Colour the boat will be displayed as on the map
*/ */
public BoatInRace(String name, double velocity, Color colour) { public BoatInRace(String name, double velocity, Color colour, String abbrev) {
super(name, velocity); super(name, velocity, abbrev);
setColour(colour); setColour(colour);
currentLegName = new SimpleStringProperty("");
} }
/** /**
@ -88,6 +92,11 @@ public class BoatInRace extends Boat {
*/ */
public void setCurrentLeg(Leg currentLeg) { public void setCurrentLeg(Leg currentLeg) {
this.currentLeg = currentLeg; this.currentLeg = currentLeg;
this.currentLegName.setValue(currentLeg.getName());
}
public StringProperty getCurrentLegName(){
return currentLegName;
} }
/** /**

@ -34,8 +34,9 @@ public class Leg {
* Construction Method * Construction Method
* @param name Name of the Leg * @param name Name of the Leg
*/ */
public Leg(String name) { public Leg(String name, int number) {
this.name = name; 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 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 * Initailiser for Race
@ -35,7 +36,7 @@ public abstract class Race implements Runnable {
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) { public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
this.startingBoats = FXCollections.observableArrayList(boats); this.startingBoats = FXCollections.observableArrayList(boats);
this.legs = legs; this.legs = legs;
this.legs.add(new Leg("Finish")); this.legs.add(new Leg("Finish", this.legs.size()));
this.controller = controller; this.controller = controller;
} }
@ -52,12 +53,16 @@ public abstract class Race implements Runnable {
* Runnable for the thread. * Runnable for the thread.
*/ */
public void run() { public void run() {
updateController(); setControllerListeners();
preRace(); preRace();
countdownTimer(); if(timerEnabled) countdownTimer();
simulateRace(); simulateRace();
} }
public void disableTimer() {
timerEnabled = false;
}
/** /**
* Set up the state in waiting for the race starts. * Set up the state in waiting for the race starts.
*/ */
@ -146,8 +151,8 @@ public abstract class Race implements Runnable {
} }
} }
controller.updateMap(startingBoats); if(controller != null) controller.updateMap(startingBoats);
updateTime(calcTimer()); if(timerEnabled) updateTime(calcTimer());
try { try {
timeLoopEnded = System.currentTimeMillis(); timeLoopEnded = System.currentTimeMillis();
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted)); Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
@ -178,14 +183,15 @@ public abstract class Race implements Runnable {
boat.setCurrentLeg(nextLeg); boat.setCurrentLeg(nextLeg);
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg()); boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
} }
FXCollections.sort(startingBoats, (a,b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber());
} }
} }
/** /**
* Update call for the controller. * Update call for the controller.
*/ */
protected void updateController() { protected void setControllerListeners() {
if(controller != null) controller.updateInfoTable(this); 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()); 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 * Draws the Race Map
*/ */
@ -133,7 +144,7 @@ public class ResizableRaceCanvas extends Canvas {
double height = getHeight(); double height = getHeight();
gc.clearRect(0, 0, width, height); 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); this.map = new RaceMap(32.278, -64.863, 32.320989, -64.821, (int)width, (int)height);
if (map == null){ if (map == null){
@ -166,6 +177,7 @@ public class ResizableRaceCanvas extends Canvas {
if (boat != null) { if (boat != null) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition()); // System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour()); 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="boatPlacingColumn" prefWidth="50.0" text="Place" />
<TableColumn fx:id="boatTeamColumn" prefWidth="50.0" text="Team" /> <TableColumn fx:id="boatTeamColumn" prefWidth="50.0" text="Team" />
<TableColumn fx:id="boatMarkColumn" prefWidth="50.0" text="Mark" /> <TableColumn fx:id="boatMarkColumn" prefWidth="50.0" text="Mark" />
<TableColumn fx:id="boatSpeedColumn" prefWidth="75.0" text="Speed" />
</columns> </columns>
</TableView> </TableView>
</children> </children>

@ -1,5 +1,8 @@
package seng302.Model; package seng302.Model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.paint.Color;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
@ -8,6 +11,8 @@ import seng302.Model.ConstantVelocityRace;
import seng302.Model.Leg; import seng302.Model.Leg;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Observable;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -41,4 +46,24 @@ public class RaceTest {
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs); // ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
// race.run(); // race.run();
// } // }
@Test
public void finishOrderDeterminedByVelocity() {
BoatInRace[] boats = {
new BoatInRace("NZ", 2000, Color.BEIGE, "NZ"),
new BoatInRace("AU", 2800, Color.BEIGE, "AU")
};
ArrayList<Leg> legs = new ArrayList<>();
legs.add(new Leg("Start", new GPSCoordinate(32.296577, -64.854304),new GPSCoordinate(32.293039, -64.843983),0));
legs.add(new Leg("Start", new GPSCoordinate(32.293039, -64.843983),new GPSCoordinate(32.284680, -64.850045),1));
Race race = new ConstantVelocityRace(boats, legs);
race.disableTimer();
// Boats should finish in an order determined by their velocity
Arrays.sort(boats, (a,b) -> (int)(b.getVelocity()-a.getVelocity()));
race.run();
for(int i = 0; i < boats.length; i++)
assertTrue(boats[i].equals(race.getStartingBoats().get(i)));
}
} }

Loading…
Cancel
Save