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..7e00508b 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -20,7 +20,7 @@ public class App int numberOfBoats = (int) fp.getRaceSize(); //get time scale - int timeScale = (int) fp.getTimeScale(); + double timeScale = fp.getTimeScale(); race.setTimeScale(timeScale); for (Map team : teams) { diff --git a/src/main/java/seng302/FileParser.java b/src/main/java/seng302/FileParser.java index 54586ad0..676d72ee 100644 --- a/src/main/java/seng302/FileParser.java +++ b/src/main/java/seng302/FileParser.java @@ -54,12 +54,13 @@ public class FileParser { * negative number, or containing non numeric character) or cannot be found. */ @SuppressWarnings("unchecked") - public long getTimeScale() { + public double getTimeScale() { try { - long timeScale = (long) this.content.get("time-scale"); + double timeScale = (double) this.content.get("time-scale"); return timeScale >= 0 ? timeScale : -1; } catch (Exception e) { - return -1; + e.printStackTrace(); + return 1; } } diff --git a/src/main/java/seng302/Race.java b/src/main/java/seng302/Race.java index e457e718..13fb898e 100644 --- a/src/main/java/seng302/Race.java +++ b/src/main/java/seng302/Race.java @@ -11,7 +11,7 @@ public class Race { private PriorityQueue events; // The events that occur in the race private int numberOfBoats = 0; private long startTime = 0; - private int timeScale = 1; + private double timeScale = 1; public Race() { this.boats = new ArrayList(); @@ -141,7 +141,7 @@ public class Race { * Sets time scale * @param timeScale */ - public void setTimeScale(int timeScale) { + public void setTimeScale(double timeScale) { this.timeScale = timeScale; } @@ -171,7 +171,7 @@ public class Race { */ public float getDistanceTravelled(long velocity) { long timeDiff = System.currentTimeMillis() - this.startTime; - long timeElapse = timeDiff / 1000 * this.timeScale; + long timeElapse = (long) (timeDiff / 1000 * this.timeScale); return timeElapse * velocity; } @@ -183,7 +183,7 @@ public class Race { // iterates all events. ends when no event in events. while (!events.isEmpty()) { Event peekEvent = events.peek(); - long currentTime = (System.currentTimeMillis() - this.startTime) * this.timeScale; + long currentTime = (long) ((System.currentTimeMillis() - this.startTime) * this.timeScale); if (currentTime > peekEvent.getTime()) { // pull out the event