From 12a9205ded303078c1783cacba73bf27f8434313 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Mon, 20 Mar 2017 16:11:02 +1300 Subject: [PATCH 1/6] Implemented Table Refresh Function - Made refreshTable() in RaceController that refresh the boatInfoTable - Made checkPosition() in Race call controller.refreshTable() - Result is that the table now updates #story [15] --- src/main/java/seng302/Controllers/RaceController.java | 11 +++++++---- src/main/java/seng302/Model/Race.java | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java index 00731eac..184ceb82 100644 --- a/src/main/java/seng302/Controllers/RaceController.java +++ b/src/main/java/seng302/Controllers/RaceController.java @@ -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,7 +39,7 @@ public class RaceController extends Controller{ Label timer; @FXML - TableView boatInfoTable; + TableView boatInfoTable; @FXML TableColumn boatPlacingColumn; @FXML @@ -65,7 +64,7 @@ public class RaceController extends Controller{ * @param race Race to listen to. */ public void updateInfoTable(Race race) { - boatInfoTable.getItems().clear(); + //boatInfoTable.getItems().clear(); boatInfoTable.setItems(race.getStartingBoats()); boatTeamColumn.setCellValueFactory(new PropertyValueFactory("Name")); @@ -78,6 +77,10 @@ public class RaceController extends Controller{ }); } + public void refreshTable(){ + boatInfoTable.refresh(); + } + @Override public void initialize(URL location, ResourceBundle resources) { @@ -119,7 +122,7 @@ public class RaceController extends Controller{ boat1.setColour(Color.DARKVIOLET); boat1.setCurrentPosition(new GPSCoordinate(0, 0)); - BoatInRace boat2 = new BoatInRace("TEST", 400); + BoatInRace boat2 = new BoatInRace("TEST", 300); boat2.setColour(Color.DARKRED); boat2.setCurrentPosition(new GPSCoordinate(0, 0)); diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 47343dfb..b4f35a77 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -135,7 +135,6 @@ public abstract class Race implements Runnable { */ protected void checkPosition(BoatInRace boat, long timeElapsed) { if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){ - //updateController(); removed as we do not update the table every time anymore. //boat has passed onto new leg if (boat.getCurrentLeg().getName().equals("Finish")) { //boat has finished @@ -147,6 +146,7 @@ public abstract class Race implements Runnable { boat.setCurrentLeg(nextLeg); boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg()); } + controller.refreshTable(); } } From 98c5c4656979411a618e9af5268c0364ee77ba74 Mon Sep 17 00:00:00 2001 From: David Wu Date: Mon, 20 Mar 2017 16:46:59 +1300 Subject: [PATCH 2/6] Implemented displayText to display boat name and speed with mark -method takes in boat name, boat speed and coordinates #story [18, 19] --- src/main/java/seng302/Model/Race.java | 2 +- src/main/java/seng302/Model/ResizableRaceCanvas.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 96fb96cc..dbaa64de 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -25,7 +25,7 @@ public abstract class Race implements Runnable { private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop - private int PRERACE_TIME = Integer.MAX_VALUE; //time in milliseconds to pause during pre-race + private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race /** * Initailiser for Race diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java index 9cbd403f..06682736 100644 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -124,6 +124,16 @@ 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 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 */ @@ -166,6 +176,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.getName(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); } } } From 293f63ca8bcc8c7f1006d8d36160c43c07098c27 Mon Sep 17 00:00:00 2001 From: David Wu Date: Mon, 20 Mar 2017 17:08:25 +1300 Subject: [PATCH 3/6] Added abbreviations to each boat -BoatInRace now takes extra parameter "abbrev" #story [18] --- src/main/java/seng302/Constants.java | 12 ++++++------ src/main/java/seng302/Model/Boat.java | 6 +++++- src/main/java/seng302/Model/BoatInRace.java | 4 ++-- src/main/java/seng302/Model/Race.java | 2 +- src/main/java/seng302/Model/ResizableRaceCanvas.java | 9 +++++---- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/seng302/Constants.java b/src/main/java/seng302/Constants.java index 0db52afb..e7569a13 100644 --- a/src/main/java/seng302/Constants.java +++ b/src/main/java/seng302/Constants.java @@ -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", 200.0, Color.BLUEVIOLET), - new BoatInRace("Land Rover BAR", 180.0, Color.BLACK), - new BoatInRace("SoftBank Team Japan", 190.0, Color.RED), - new BoatInRace("Groupama Team France", 210.0, Color.ORANGE), - new BoatInRace("Artemis Racing", 220.0, Color.DARKOLIVEGREEN), - new BoatInRace("Emirates Team New Zealand", 310, Color.LIMEGREEN)}; + {new BoatInRace("Oracle Team USA", 200.0, Color.BLUEVIOLET, "USA"), + new BoatInRace("Land Rover BAR", 180.0, Color.BLACK, "BAR"), + new BoatInRace("SoftBank Team Japan", 190.0, Color.RED, "JAP"), + new BoatInRace("Groupama Team France", 210.0, Color.ORANGE, "FRN"), + new BoatInRace("Artemis Racing", 220.0, Color.DARKOLIVEGREEN, "ART"), + new BoatInRace("Emirates Team New Zealand", 310, Color.LIMEGREEN, "ENZ")}; //public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new ) } diff --git a/src/main/java/seng302/Model/Boat.java b/src/main/java/seng302/Model/Boat.java index 25d67520..1c4d0484 100644 --- a/src/main/java/seng302/Model/Boat.java +++ b/src/main/java/seng302/Model/Boat.java @@ -8,15 +8,17 @@ import java.util.ArrayList; public class Boat { private String name; private double velocity; + 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.abbrev = abbrev; } /** @@ -43,4 +45,6 @@ public class Boat { return getName(); } + public String getAbbrev() { return abbrev; } + } diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index 0c278222..c7ae531a 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -25,8 +25,8 @@ 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); } diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 2e824982..e6105d78 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -24,7 +24,7 @@ public abstract class Race implements Runnable { protected long totalTimeElapsed; - private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop + private int SLEEP_TIME = 50; //time in milliseconds to pause in a paced loop private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race /** diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java index e3b87665..bcb44e1e 100644 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -126,11 +126,12 @@ public class ResizableRaceCanvas extends Canvas { /** * Display given name and speed of boat at a graph coordinate - * @param name name of boat + * @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"; + String text = name + ", " + speed + " knots"; gc.fillText(text, coordinate.getX()+20, coordinate.getY()); } @@ -143,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){ @@ -176,7 +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.getName(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); + displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); } } } From c8fcada4272bb21ad48b7b69c16fdef5de7114f3 Mon Sep 17 00:00:00 2001 From: cbt24 Date: Mon, 20 Mar 2017 17:26:13 +1300 Subject: [PATCH 4/6] Fixed sort order for boats in race - Sort boats by leg number (preserves order when boats enter shared leg) #story [19] --- src/main/java/seng302/Model/Race.java | 3 ++- src/main/java/seng302/Model/ResizableRaceCanvas.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index f87b0991..589edff0 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -24,7 +24,7 @@ public abstract class Race implements Runnable { protected long totalTimeElapsed; - private int SLEEP_TIME = 25; //time in milliseconds to pause in a paced loop + private int SLEEP_TIME = 50; //time in milliseconds to pause in a paced loop private int PRERACE_TIME = 10000;//Integer.MAX_VALUE; //time in milliseconds to pause during pre-race /** @@ -177,6 +177,7 @@ public abstract class Race implements Runnable { boat.setCurrentLeg(nextLeg); boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg()); } + FXCollections.sort(startingBoats, (a,b) -> b.getCurrentLeg().getLegNumber() - a.getCurrentLeg().getLegNumber()); } } diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java index e3b87665..d85c3a4e 100644 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -143,7 +143,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){ @@ -176,7 +176,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.getName(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); + displayText(boat.getName().getValue(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); } } } From 13c5c12db3d084beb6c4a73cde625182e55c86f8 Mon Sep 17 00:00:00 2001 From: David Wu Date: Mon, 20 Mar 2017 17:27:09 +1300 Subject: [PATCH 5/6] Added table column to display speed of each boat -BoatInRace now has a column to called boatSpeedColumn that displays boat #story [17] #pair[fwy13, zwu18] --- src/main/java/seng302/Controllers/RaceController.java | 3 +++ src/main/java/seng302/Model/Boat.java | 8 ++++++++ src/main/resources/scenes/racepane.fxml | 1 + 3 files changed, 12 insertions(+) diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java index 57f96474..317d69da 100644 --- a/src/main/java/seng302/Controllers/RaceController.java +++ b/src/main/java/seng302/Controllers/RaceController.java @@ -46,6 +46,8 @@ public class RaceController extends Controller{ TableColumn boatTeamColumn; @FXML TableColumn boatMarkColumn; + @FXML + TableColumn boatSpeedColumn; /** * updates the ResizableRaceCanvas (raceMap) with most recent data @@ -68,6 +70,7 @@ public class RaceController extends Controller{ boatInfoTable.setItems(race.getStartingBoats()); boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); + boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp()); boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName()); boatPlacingColumn.setCellValueFactory(new Callback, ObservableValue>() { @Override diff --git a/src/main/java/seng302/Model/Boat.java b/src/main/java/seng302/Model/Boat.java index 12ed8279..4cd2503b 100644 --- a/src/main/java/seng302/Model/Boat.java +++ b/src/main/java/seng302/Model/Boat.java @@ -1,5 +1,7 @@ package seng302.Model; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; @@ -11,6 +13,7 @@ import java.util.ArrayList; public class Boat { private StringProperty name; private double velocity; + private StringProperty velocityProp; private String abbrev; /** @@ -20,6 +23,7 @@ public class Boat { */ public Boat(String name, double velocity, String abbrev){ this.velocity = velocity; + this.velocityProp = new SimpleStringProperty(String.valueOf(velocity)); this.abbrev = abbrev; this.name = new SimpleStringProperty(name); } @@ -52,6 +56,10 @@ public class Boat { return getName().getValue(); } + public StringProperty getVelocityProp() { + return velocityProp; + } + public String getAbbrev() { return abbrev; } } diff --git a/src/main/resources/scenes/racepane.fxml b/src/main/resources/scenes/racepane.fxml index d699ff46..ed538a38 100644 --- a/src/main/resources/scenes/racepane.fxml +++ b/src/main/resources/scenes/racepane.fxml @@ -20,6 +20,7 @@ + From 26f7b94e13fd16bf7750a362ab1aa65bc126bfa0 Mon Sep 17 00:00:00 2001 From: Connor Taylor-Brown Date: Mon, 20 Mar 2017 20:18:32 +1300 Subject: [PATCH 6/6] Fixed finish order - Added test to check order is determined by velocity - Modified Race class to allow for unit testing #story[15] --- src/main/java/seng302/Model/Leg.java | 3 ++- src/main/java/seng302/Model/Race.java | 13 ++++++++---- src/test/java/seng302/Model/RaceTest.java | 25 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/java/seng302/Model/Leg.java b/src/main/java/seng302/Model/Leg.java index 0d1f5649..84ee1529 100644 --- a/src/main/java/seng302/Model/Leg.java +++ b/src/main/java/seng302/Model/Leg.java @@ -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; } /** diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 589edff0..97c675f5 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -26,6 +26,7 @@ public abstract class Race implements Runnable { private int SLEEP_TIME = 50; //time in milliseconds to pause in a paced loop 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 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; } @@ -54,10 +55,14 @@ public abstract class Race implements Runnable { public void run() { 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)); diff --git a/src/test/java/seng302/Model/RaceTest.java b/src/test/java/seng302/Model/RaceTest.java index 0ead45f7..f448d092 100644 --- a/src/test/java/seng302/Model/RaceTest.java +++ b/src/test/java/seng302/Model/RaceTest.java @@ -1,5 +1,8 @@ package seng302.Model; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.paint.Color; import org.junit.Ignore; import org.junit.Test; import seng302.GPSCoordinate; @@ -8,6 +11,8 @@ import seng302.Model.ConstantVelocityRace; import seng302.Model.Leg; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Observable; import static org.junit.Assert.assertTrue; @@ -41,4 +46,24 @@ public class RaceTest { // ConstantVelocityRace race = new ConstantVelocityRace(boats, legs); // race.run(); // } + + @Test + public void finishOrderDeterminedByVelocity() { + BoatInRace[] boats = { + new BoatInRace("NZ", 2000, Color.BEIGE, "NZ"), + new BoatInRace("AU", 2800, Color.BEIGE, "AU") + }; + ArrayList 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))); + } }