Fixed incorrect headings and velocity display location

- Velocity is now shown in the list of starting boats #fix
- Headings have been corrected

Tags: #fix
This commit is contained in:
Michael Rausch
2017-03-08 14:11:09 +13:00
parent 2adf39ee43
commit 92556fffca
4 changed files with 33 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"race-name": "AC35",
"time-scale": 1000,
"time-scale": 1,
"race-size": 4,
"teams": [
{"team-name": "Oracle Team USA", "velocity": 20.9},
+4 -4
View File
@@ -39,12 +39,12 @@ public class App
race.addBoat(new Boat(boatNames.get(i), (Double)(teams.get(i).get("velocity"))));
}
race.addLeg(new Leg(035, 100, "Start"));
race.addLeg(new Leg(010, 300, "Marker 1"));
race.addLeg(new Leg(35, 100, "Start"));
race.addLeg(new Leg(10, 300, "Marker 1"));
race.addLeg(new Leg(350, 400, "Leeward Gate"));
race.addLeg(new Leg(010, 400, "Windward Gate"));
race.addLeg(new Leg(10, 400, "Windward Gate"));
Leg finishingLeg = new Leg(010, 400, "Leeward Gate");
Leg finishingLeg = new Leg(10, 400, "Leeward Gate");
finishingLeg.setFinishingLeg(true);
race.addLeg(finishingLeg);
+20
View File
@@ -16,6 +16,7 @@ public class Event {
private long time;
private Boat boat;
private Leg leg;
private boolean isFinishingEvent = false;
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
this.time = eventTime;
@@ -23,6 +24,13 @@ public class Event {
this.leg = eventLeg;
}
public Event(long eventTime, Boat eventBoat, Leg eventLeg, boolean isFinishingEvent) {
this.time = eventTime;
this.boat = eventBoat;
this.leg = eventLeg;
this.isFinishingEvent = isFinishingEvent;
}
/**
* Sets the time for the event
* @param eventTime the time for event in millisecond
@@ -87,6 +95,14 @@ public class Event {
this.leg.addBoatToMarker(boat);
}
/**
* Returns true if this event is the boat finishing the race
*
*/
public boolean getIsFinishingEvent(){
return this.isFinishingEvent;
}
/**
* Get a string that contains the timestamp and course information for this event
* @return A string that contains the timestamp and course information for this event
@@ -94,6 +110,10 @@ public class Event {
public String getEventString(){
String currentHeading = Integer.toString(this.getLeg().getHeading());
if (this.isFinishingEvent){
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
}
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.getLeg().getMarkerLabel() + " going heading " + currentHeading + "°");
}
}
+8 -1
View File
@@ -158,6 +158,13 @@ public class Race {
Event event = new Event(time, boat, leg);
events.add(event);
totalDistance += leg.getDistance();
// If finishing leg, add another event for when the boat finishes the race
if (leg.getIsFinishingLeg()){
time = (long) (1000 * totalDistance / boat.getVelocity());
event = new Event(time, boat, leg, true);
events.add(event);
}
}
}
}
@@ -193,7 +200,7 @@ public class Race {
System.out.println(nextEvent.getEventString());
nextEvent.addBoatToMarker();
if (nextEvent.getLeg().getIsFinishingLeg()){
if (nextEvent.getIsFinishingEvent()){
this.finishingOrder.add(nextEvent.getBoat());
}
}