Added two test boats to race
#story[9] #implement
This commit is contained in:
Generated
+17
-1
@@ -1,11 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
|
<resourceExtensions />
|
||||||
|
<wildcardResourcePatterns>
|
||||||
|
<entry name="!?*.java" />
|
||||||
|
<entry name="!?*.form" />
|
||||||
|
<entry name="!?*.class" />
|
||||||
|
<entry name="!?*.groovy" />
|
||||||
|
<entry name="!?*.scala" />
|
||||||
|
<entry name="!?*.flex" />
|
||||||
|
<entry name="!?*.kt" />
|
||||||
|
<entry name="!?*.clj" />
|
||||||
|
<entry name="!?*.aj" />
|
||||||
|
</wildcardResourcePatterns>
|
||||||
<annotationProcessing>
|
<annotationProcessing>
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
<profile default="true" name="Default" enabled="false">
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
</profile>
|
||||||
|
<profile default="false" name="Maven default annotation processors profile" enabled="true">
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
<module name="team-7" />
|
<module name="team-7" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
|
|||||||
Generated
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/team-7.iml" filepath="$PROJECT_DIR$/.idea/team-7.iml" />
|
<module fileurl="file://$PROJECT_DIR$/team-7.iml" filepath="$PROJECT_DIR$/team-7.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,6 +4,7 @@ package seng302.Controllers;
|
|||||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
@@ -47,15 +48,16 @@ public class RaceController extends Controller{
|
|||||||
private RaceMap map;
|
private RaceMap map;
|
||||||
|
|
||||||
|
|
||||||
public void updateMap(ArrayList<BoatInRace> boats) {
|
public void updateMap(ObservableList<BoatInRace> boats) {
|
||||||
raceMap.setBoats(boats);
|
BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
|
||||||
|
raceMap.setBoats(boats.toArray(boatInRaces));
|
||||||
raceMap.drawRaceMap();
|
raceMap.drawRaceMap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateInfoTable(Race race) {
|
public void updateInfoTable(Race race) {
|
||||||
boatInfoTable.getItems().clear();
|
boatInfoTable.getItems().clear();
|
||||||
boatInfoTable.setItems(FXCollections.observableArrayList(race.getStartingBoats()));
|
boatInfoTable.setItems(race.getStartingBoats());
|
||||||
|
|
||||||
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
||||||
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
||||||
@@ -70,7 +72,7 @@ public class RaceController extends Controller{
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
ArrayList<BoatInRace> boats = generateAC35Competitors();
|
BoatInRace[] boats = generateAC35Competitors();
|
||||||
|
|
||||||
raceMap = new ResizableRaceCanvas();
|
raceMap = new ResizableRaceCanvas();
|
||||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||||
@@ -98,18 +100,21 @@ public class RaceController extends Controller{
|
|||||||
return legs;
|
return legs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<BoatInRace> generateAC35Competitors() {
|
private BoatInRace[] generateAC35Competitors() {
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
|
||||||
|
|
||||||
BoatInRace nz = new BoatInRace("NZ", 50);
|
BoatInRace boat1 = new BoatInRace("NZ", 500);
|
||||||
nz.setColour(Color.DARKVIOLET);
|
boat1.setColour(Color.DARKVIOLET);
|
||||||
nz.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat1.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
boats.add(nz);
|
|
||||||
|
|
||||||
//do the rest
|
BoatInRace boat2 = new BoatInRace("TEST", 400);
|
||||||
|
boat2.setColour(Color.DARKRED);
|
||||||
|
boat2.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
|
|
||||||
|
BoatInRace boat3 = new BoatInRace("TEST2", 350);
|
||||||
|
boat3.setColour(Color.FUCHSIA);
|
||||||
|
boat3.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
|
return new BoatInRace[] {boat1, boat2, boat3};
|
||||||
|
|
||||||
return boats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package seng302.Model;
|
|||||||
|
|
||||||
import seng302.Constants;
|
import seng302.Constants;
|
||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
@@ -23,11 +21,11 @@ public class ConstantVelocityRace extends Race {
|
|||||||
* @see Leg
|
* @see Leg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public ConstantVelocityRace(ArrayList<BoatInRace> startingBoats, ArrayList<Leg> marks, RaceController controller) {
|
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks, RaceController controller) {
|
||||||
super(startingBoats, marks, controller);
|
super(startingBoats, marks, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstantVelocityRace(ArrayList<BoatInRace> startingBoats, ArrayList<Leg> marks) {
|
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks) {
|
||||||
super(startingBoats, marks);
|
super(startingBoats, marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableArray;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
@@ -11,7 +14,8 @@ import java.util.*;
|
|||||||
* Created by fwy13 on 3/03/17.
|
* Created by fwy13 on 3/03/17.
|
||||||
*/
|
*/
|
||||||
public abstract class Race implements Runnable {
|
public abstract class Race implements Runnable {
|
||||||
protected ArrayList<BoatInRace> startingBoats;
|
//protected BoatInRace[] startingBoats;
|
||||||
|
protected ObservableList<BoatInRace> startingBoats;
|
||||||
protected ArrayList<Leg> legs;
|
protected ArrayList<Leg> legs;
|
||||||
protected RaceController controller;
|
protected RaceController controller;
|
||||||
protected int boatsFinished = 0;
|
protected int boatsFinished = 0;
|
||||||
@@ -24,14 +28,14 @@ public abstract class Race implements Runnable {
|
|||||||
* @param boats Takes in an array of boats that are participating in the race.
|
* @param boats Takes in an array of boats that are participating in the race.
|
||||||
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||||
*/
|
*/
|
||||||
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> legs, RaceController controller) {
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||||
this.startingBoats = 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.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> marks) {
|
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
|
||||||
this(boats, marks, null);
|
this(boats, marks, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,9 +50,10 @@ public abstract class Race implements Runnable {
|
|||||||
System.out.println("Boats Participating:");
|
System.out.println("Boats Participating:");
|
||||||
System.out.println("====================");
|
System.out.println("====================");
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " +
|
if (startingBoats.get(i) != null) {
|
||||||
Math.round(startingBoats.get(i).getVelocity()) + "kn");
|
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " + Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn");
|
||||||
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +84,10 @@ public abstract class Race implements Runnable {
|
|||||||
System.out.println(minutes + ":" + remainingSeconds);
|
System.out.println(minutes + ":" + remainingSeconds);
|
||||||
|
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
updatePosition(boat, SLEEP_TIME);
|
if (boat != null) {
|
||||||
checkPosition(boat, totalTimeElapsed);
|
updatePosition(boat, SLEEP_TIME);
|
||||||
|
checkPosition(boat, totalTimeElapsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.updateMap(startingBoats);
|
controller.updateMap(startingBoats);
|
||||||
@@ -96,7 +103,6 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
||||||
updateController();
|
|
||||||
//boat has passed onto new leg
|
//boat has passed onto new leg
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
//boat has finished
|
//boat has finished
|
||||||
@@ -116,7 +122,7 @@ public abstract class Race implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<BoatInRace> getStartingBoats() {
|
public ObservableList<BoatInRace> getStartingBoats() {
|
||||||
return startingBoats;
|
return startingBoats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import java.util.Random;
|
|||||||
public class ResizableRaceCanvas extends Canvas {
|
public class ResizableRaceCanvas extends Canvas {
|
||||||
GraphicsContext gc;
|
GraphicsContext gc;
|
||||||
RaceMap map;
|
RaceMap map;
|
||||||
private ArrayList<BoatInRace> boats = new ArrayList<>();
|
private BoatInRace[] boats;
|
||||||
|
|
||||||
public void setBoats(ArrayList<BoatInRace> boats) {
|
public void setBoats(BoatInRace[] boats) {
|
||||||
this.boats = boats;
|
this.boats = boats;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +112,10 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
if (boats != null) {
|
if (boats != null) {
|
||||||
for (BoatInRace boat : boats) {
|
for (BoatInRace boat : boats) {
|
||||||
System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
if (boat != null) {
|
||||||
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
||||||
|
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,18 @@ import static org.junit.Assert.assertTrue;
|
|||||||
public class RaceTest {
|
public class RaceTest {
|
||||||
|
|
||||||
|
|
||||||
@Ignore
|
// @Ignore
|
||||||
@Test
|
// @Test
|
||||||
public void singleBoatRaceRunsAndFinishes(){
|
// public void singleBoatRaceRunsAndFinishes(){
|
||||||
|
//
|
||||||
BoatInRace boat = new BoatInRace("NZ", 240);
|
// BoatInRace boat = new BoatInRace("NZ", 240);
|
||||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||||
boats.add(boat);
|
// boats.add(boat);
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
// ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
// legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
||||||
race.run();
|
// race.run();
|
||||||
}
|
// }
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
// public void fasterBoatFinishesFirst() {
|
// public void fasterBoatFinishesFirst() {
|
||||||
|
|||||||
Reference in New Issue
Block a user