diff --git a/doc/examples/config.json b/doc/examples/config.json index b4f4ac11..df6261b0 100644 --- a/doc/examples/config.json +++ b/doc/examples/config.json @@ -1,6 +1,6 @@ { "race-name": "AC35", - "time-scale": 1000, + "time-scale": 1.0, "race-size": 4, "teams": [ {"team-name": "Oracle Team USA", "velocity": 20.9}, diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 5f8d7292..71dde3be 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -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); diff --git a/src/main/java/seng302/Event.java b/src/main/java/seng302/Event.java index 79aada1a..13250eef 100644 --- a/src/main/java/seng302/Event.java +++ b/src/main/java/seng302/Event.java @@ -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 + "°"); } } diff --git a/src/main/java/seng302/Race.java b/src/main/java/seng302/Race.java index e457e718..8fe2c51f 100644 --- a/src/main/java/seng302/Race.java +++ b/src/main/java/seng302/Race.java @@ -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()); } }