Loaded the rest of the legs of the bermuda course in as an example race
#story[9] #implement
This commit is contained in:
@@ -14,10 +14,12 @@ public class Constants {
|
||||
|
||||
public static final GPSCoordinate mark1 = new GPSCoordinate(32.293039, -64.843983);
|
||||
|
||||
public static final GPSCoordinate leewardGate1 = new GPSCoordinate(32.284680, -64.850045);
|
||||
public static final GPSCoordinate leewardGate2 = new GPSCoordinate(32.280164, -64.847591);
|
||||
public static final GPSCoordinate windwardGate1 = new GPSCoordinate(32.309693, -64.835249);
|
||||
public static final GPSCoordinate windwardGate2 = new GPSCoordinate(32.308046, -64.831785);
|
||||
public static final GPSCoordinate windwardGate1 = new GPSCoordinate(32.284680, -64.850045);
|
||||
public static final GPSCoordinate windwardGate2 = new GPSCoordinate(32.280164, -64.847591);
|
||||
public static final GPSCoordinate leewardGate1 = new GPSCoordinate(32.309693, -64.835249);
|
||||
public static final GPSCoordinate leewardGate2 = new GPSCoordinate(32.308046, -64.831785);
|
||||
public static final GPSCoordinate finishLineMarker1 = new GPSCoordinate(32.317379, -64.839291);
|
||||
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
||||
|
||||
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class RaceController extends Controller{
|
||||
private RaceMap map;
|
||||
|
||||
|
||||
public void updateMap(BoatInRace[] boats) {
|
||||
public void updateMap(ArrayList<BoatInRace> boats) {
|
||||
raceMap.setBoats(boats);
|
||||
raceMap.drawRaceMap();
|
||||
|
||||
@@ -70,10 +70,7 @@ public class RaceController extends Controller{
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
BoatInRace boat = new BoatInRace("NZ", 400);
|
||||
boat.setColour(Color.DARKVIOLET);
|
||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
BoatInRace[] boats = new BoatInRace[] {boat};
|
||||
ArrayList<BoatInRace> boats = generateAC35Competitors();
|
||||
|
||||
raceMap = new ResizableRaceCanvas();
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
@@ -83,20 +80,37 @@ public class RaceController extends Controller{
|
||||
|
||||
canvasBase.getChildren().add(raceMap);
|
||||
|
||||
ArrayList<Leg> legs = bermudaCourseLegs();
|
||||
ArrayList<Leg> legs = generateBermudaCourseLegs();
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
|
||||
|
||||
(new Thread(race)).start();
|
||||
}
|
||||
|
||||
private ArrayList<Leg> bermudaCourseLegs() {
|
||||
private ArrayList<Leg> generateBermudaCourseLegs() {
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
|
||||
Leg leg1 = new Leg("Start to Mark 1", Constants.startLineMarker1, Constants.mark1, 0);
|
||||
Leg leg2 = new Leg("Mark 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1);
|
||||
legs.add(leg1); legs.add(leg2);
|
||||
Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2);
|
||||
Leg leg4 = new Leg("Windward Gate to Leeward Gate", Constants.windwardGate1, Constants.leewardGate1, 3);
|
||||
Leg leg5 = new Leg("Leeward Gate to Finish", Constants.leewardGate1, Constants.finishLineMarker1, 4);
|
||||
legs.add(leg1); legs.add(leg2); legs.add(leg3); legs.add(leg4); legs.add(leg5);
|
||||
return legs;
|
||||
}
|
||||
|
||||
private ArrayList<BoatInRace> generateAC35Competitors() {
|
||||
ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||
|
||||
BoatInRace nz = new BoatInRace("NZ", 50);
|
||||
nz.setColour(Color.DARKVIOLET);
|
||||
nz.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
boats.add(nz);
|
||||
|
||||
//do the rest
|
||||
|
||||
|
||||
return boats;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ public class ConstantVelocityRace extends Race {
|
||||
* @see Leg
|
||||
*/
|
||||
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks, RaceController controller) {
|
||||
public ConstantVelocityRace(ArrayList<BoatInRace> startingBoats, ArrayList<Leg> marks, RaceController controller) {
|
||||
super(startingBoats, marks, controller);
|
||||
}
|
||||
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, ArrayList<Leg> marks) {
|
||||
public ConstantVelocityRace(ArrayList<BoatInRace> startingBoats, ArrayList<Leg> marks) {
|
||||
super(startingBoats, marks);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.*;
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public abstract class Race implements Runnable {
|
||||
protected BoatInRace[] startingBoats;
|
||||
protected ArrayList<BoatInRace> startingBoats;
|
||||
protected ArrayList<Leg> legs;
|
||||
protected RaceController controller;
|
||||
protected int boatsFinished = 0;
|
||||
@@ -24,14 +24,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(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> legs, RaceController controller) {
|
||||
this.startingBoats = boats;
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish"));
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
|
||||
public Race(ArrayList<BoatInRace> boats, ArrayList<Leg> marks) {
|
||||
this(boats, marks, null);
|
||||
}
|
||||
|
||||
@@ -45,9 +45,10 @@ public abstract class Race implements Runnable {
|
||||
//show the boats participating.
|
||||
System.out.println("Boats Participating:");
|
||||
System.out.println("====================");
|
||||
for (int i = 0; i < startingBoats.length; i++) {
|
||||
System.out.println(i + 1 + ". " + startingBoats[i].getName() + ", Speed: " + Math.round(startingBoats[i].getVelocity() * 1.94384) + "kn");
|
||||
startingBoats[i].setCurrentLeg(legs.get(0));
|
||||
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");
|
||||
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ public abstract class Race implements Runnable {
|
||||
long remainingSeconds;
|
||||
|
||||
|
||||
while (boatsFinished < startingBoats.length) {
|
||||
while (boatsFinished < startingBoats.size()) {
|
||||
timeLoopStarted = System.currentTimeMillis();
|
||||
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||
long currentTime = System.currentTimeMillis() - timeRaceStarted;
|
||||
@@ -115,7 +116,7 @@ public abstract class Race implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
public BoatInRace[] getStartingBoats() {
|
||||
public ArrayList<BoatInRace> getStartingBoats() {
|
||||
return startingBoats;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
import seng302.RaceMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -19,9 +20,9 @@ import java.util.Random;
|
||||
public class ResizableRaceCanvas extends Canvas {
|
||||
GraphicsContext gc;
|
||||
RaceMap map;
|
||||
private BoatInRace[] boats;
|
||||
private ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||
|
||||
public void setBoats(BoatInRace[] boats) {
|
||||
public void setBoats(ArrayList<BoatInRace> boats) {
|
||||
this.boats = boats;
|
||||
}
|
||||
|
||||
@@ -90,8 +91,8 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
|
||||
//finish line
|
||||
gc.setLineWidth(2);
|
||||
GraphCoordinate finishLineCoord1 = this.map.convertGPS(32.317379, -64.839291);
|
||||
GraphCoordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
||||
GraphCoordinate finishLineCoord1 = this.map.convertGPS(Constants.finishLineMarker1);
|
||||
GraphCoordinate finishLineCoord2 = this.map.convertGPS(Constants.finishLineMarker2);
|
||||
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
|
||||
//marks
|
||||
GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1);
|
||||
|
||||
Reference in New Issue
Block a user