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"?>
|
||||
<project version="4">
|
||||
<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>
|
||||
<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" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<processorPath useClasspath="true" />
|
||||
<module name="team-7" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
|
||||
Generated
+1
-1
@@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<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>
|
||||
</component>
|
||||
</project>
|
||||
@@ -4,6 +4,7 @@ package seng302.Controllers;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.control.TableColumn;
|
||||
@@ -47,15 +48,16 @@ public class RaceController extends Controller{
|
||||
private RaceMap map;
|
||||
|
||||
|
||||
public void updateMap(ArrayList<BoatInRace> boats) {
|
||||
raceMap.setBoats(boats);
|
||||
public void updateMap(ObservableList<BoatInRace> boats) {
|
||||
BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
|
||||
raceMap.setBoats(boats.toArray(boatInRaces));
|
||||
raceMap.drawRaceMap();
|
||||
|
||||
}
|
||||
|
||||
public void updateInfoTable(Race race) {
|
||||
boatInfoTable.getItems().clear();
|
||||
boatInfoTable.setItems(FXCollections.observableArrayList(race.getStartingBoats()));
|
||||
boatInfoTable.setItems(race.getStartingBoats());
|
||||
|
||||
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
||||
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
||||
@@ -70,7 +72,7 @@ public class RaceController extends Controller{
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
ArrayList<BoatInRace> boats = generateAC35Competitors();
|
||||
BoatInRace[] boats = generateAC35Competitors();
|
||||
|
||||
raceMap = new ResizableRaceCanvas();
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
@@ -98,18 +100,21 @@ public class RaceController extends Controller{
|
||||
return legs;
|
||||
}
|
||||
|
||||
private ArrayList<BoatInRace> generateAC35Competitors() {
|
||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||
private BoatInRace[] generateAC35Competitors() {
|
||||
|
||||
BoatInRace nz = new BoatInRace("NZ", 50);
|
||||
nz.setColour(Color.DARKVIOLET);
|
||||
nz.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
boats.add(nz);
|
||||
BoatInRace boat1 = new BoatInRace("NZ", 500);
|
||||
boat1.setColour(Color.DARKVIOLET);
|
||||
boat1.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
|
||||
//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.Controllers.RaceController;
|
||||
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
@@ -23,11 +21,11 @@ public class ConstantVelocityRace extends Race {
|
||||
* @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);
|
||||
}
|
||||
|
||||
public ConstantVelocityRace(ArrayList<BoatInRace> startingBoats, ArrayList<Leg> marks) {
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks) {
|
||||
super(startingBoats, marks);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package seng302.Model;
|
||||
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableArray;
|
||||
import javafx.collections.ObservableList;
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
@@ -11,7 +14,8 @@ import java.util.*;
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public abstract class Race implements Runnable {
|
||||
protected ArrayList<BoatInRace> startingBoats;
|
||||
//protected BoatInRace[] startingBoats;
|
||||
protected ObservableList<BoatInRace> startingBoats;
|
||||
protected ArrayList<Leg> legs;
|
||||
protected RaceController controller;
|
||||
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 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) {
|
||||
this.startingBoats = boats;
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish"));
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> marks) {
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
|
||||
this(boats, marks, null);
|
||||
}
|
||||
|
||||
@@ -46,11 +50,12 @@ public abstract class Race implements Runnable {
|
||||
System.out.println("Boats Participating:");
|
||||
System.out.println("====================");
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " +
|
||||
Math.round(startingBoats.get(i).getVelocity()) + "kn");
|
||||
if (startingBoats.get(i) != null) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -79,9 +84,11 @@ public abstract class Race implements Runnable {
|
||||
System.out.println(minutes + ":" + remainingSeconds);
|
||||
|
||||
for (BoatInRace boat : startingBoats) {
|
||||
if (boat != null) {
|
||||
updatePosition(boat, SLEEP_TIME);
|
||||
checkPosition(boat, totalTimeElapsed);
|
||||
}
|
||||
}
|
||||
|
||||
controller.updateMap(startingBoats);
|
||||
try {
|
||||
@@ -96,7 +103,6 @@ public abstract class Race implements Runnable {
|
||||
|
||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
||||
updateController();
|
||||
//boat has passed onto new leg
|
||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||
//boat has finished
|
||||
@@ -116,7 +122,7 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<BoatInRace> getStartingBoats() {
|
||||
public ObservableList<BoatInRace> getStartingBoats() {
|
||||
return startingBoats;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ import java.util.Random;
|
||||
public class ResizableRaceCanvas extends Canvas {
|
||||
GraphicsContext gc;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -112,10 +112,12 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
|
||||
if (boats != null) {
|
||||
for (BoatInRace boat : boats) {
|
||||
if (boat != null) {
|
||||
System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
|
||||
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//display wind direction arrow - specify origin point and angle
|
||||
displayArrow(new GraphCoordinate(500, 20), 100);
|
||||
|
||||
@@ -17,18 +17,18 @@ import static org.junit.Assert.assertTrue;
|
||||
public class RaceTest {
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void singleBoatRaceRunsAndFinishes(){
|
||||
|
||||
BoatInRace boat = new BoatInRace("NZ", 240);
|
||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||
boats.add(boat);
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
||||
race.run();
|
||||
}
|
||||
// @Ignore
|
||||
// @Test
|
||||
// public void singleBoatRaceRunsAndFinishes(){
|
||||
//
|
||||
// BoatInRace boat = new BoatInRace("NZ", 240);
|
||||
// ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||
// boats.add(boat);
|
||||
// ArrayList<Leg> legs = new ArrayList<>();
|
||||
// legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
||||
// ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
||||
// race.run();
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void fasterBoatFinishesFirst() {
|
||||
|
||||
Reference in New Issue
Block a user