mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge branch 'fix-headings'
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"race-name": "AC35",
|
"race-name": "AC35",
|
||||||
"time-scale": 1000,
|
"time-scale": 1.0,
|
||||||
"race-size": 4,
|
"race-size": 4,
|
||||||
"teams": [
|
"teams": [
|
||||||
{"team-name": "Oracle Team USA", "velocity": 20.9},
|
{"team-name": "Oracle Team USA", "velocity": 20.9},
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ public class App
|
|||||||
race.addBoat(new Boat(boatNames.get(i), (Double)(teams.get(i).get("velocity"))));
|
race.addBoat(new Boat(boatNames.get(i), (Double)(teams.get(i).get("velocity"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
race.addLeg(new Leg(035, 100, "Start"));
|
race.addLeg(new Leg(35, 100, "Start"));
|
||||||
race.addLeg(new Leg(010, 300, "Marker 1"));
|
race.addLeg(new Leg(10, 300, "Marker 1"));
|
||||||
race.addLeg(new Leg(350, 400, "Leeward Gate"));
|
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);
|
finishingLeg.setFinishingLeg(true);
|
||||||
|
|
||||||
race.addLeg(finishingLeg);
|
race.addLeg(finishingLeg);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class Event {
|
|||||||
private long time;
|
private long time;
|
||||||
private Boat boat;
|
private Boat boat;
|
||||||
private Leg leg;
|
private Leg leg;
|
||||||
|
private boolean isFinishingEvent = false;
|
||||||
|
|
||||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
|
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
|
||||||
this.time = eventTime;
|
this.time = eventTime;
|
||||||
@@ -23,6 +24,13 @@ public class Event {
|
|||||||
this.leg = eventLeg;
|
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
|
* Sets the time for the event
|
||||||
* @param eventTime the time for event in millisecond
|
* @param eventTime the time for event in millisecond
|
||||||
@@ -87,6 +95,14 @@ public class Event {
|
|||||||
this.leg.addBoatToMarker(boat);
|
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
|
* 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
|
* @return A string that contains the timestamp and course information for this event
|
||||||
@@ -94,6 +110,10 @@ public class Event {
|
|||||||
public String getEventString(){
|
public String getEventString(){
|
||||||
String currentHeading = Integer.toString(this.getLeg().getHeading());
|
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 + "°");
|
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.getLeg().getMarkerLabel() + " going heading " + currentHeading + "°");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,6 +158,13 @@ public class Race {
|
|||||||
Event event = new Event(time, boat, leg);
|
Event event = new Event(time, boat, leg);
|
||||||
events.add(event);
|
events.add(event);
|
||||||
totalDistance += leg.getDistance();
|
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());
|
System.out.println(nextEvent.getEventString());
|
||||||
nextEvent.addBoatToMarker();
|
nextEvent.addBoatToMarker();
|
||||||
|
|
||||||
if (nextEvent.getLeg().getIsFinishingLeg()){
|
if (nextEvent.getIsFinishingEvent()){
|
||||||
this.finishingOrder.add(nextEvent.getBoat());
|
this.finishingOrder.add(nextEvent.getBoat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user