This commit is contained in:
Michael Rausch
2017-03-08 14:20:38 +13:00
3 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ public class App
int numberOfBoats = (int) fp.getRaceSize(); int numberOfBoats = (int) fp.getRaceSize();
//get time scale //get time scale
int timeScale = (int) fp.getTimeScale(); double timeScale = fp.getTimeScale();
race.setTimeScale(timeScale); race.setTimeScale(timeScale);
for (Map<String, Object> team : teams) { for (Map<String, Object> team : teams) {
+4 -3
View File
@@ -54,12 +54,13 @@ public class FileParser {
* negative number, or containing non numeric character) or cannot be found. * negative number, or containing non numeric character) or cannot be found.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public long getTimeScale() { public double getTimeScale() {
try { try {
long timeScale = (long) this.content.get("time-scale"); double timeScale = (double) this.content.get("time-scale");
return timeScale >= 0 ? timeScale : -1; return timeScale >= 0 ? timeScale : -1;
} catch (Exception e) { } catch (Exception e) {
return -1; e.printStackTrace();
return 1;
} }
} }
+4 -4
View File
@@ -11,7 +11,7 @@ public class Race {
private PriorityQueue<Event> events; // The events that occur in the race private PriorityQueue<Event> events; // The events that occur in the race
private int numberOfBoats = 0; private int numberOfBoats = 0;
private long startTime = 0; private long startTime = 0;
private int timeScale = 1; private double timeScale = 1;
public Race() { public Race() {
this.boats = new ArrayList<Boat>(); this.boats = new ArrayList<Boat>();
@@ -141,7 +141,7 @@ public class Race {
* Sets time scale * Sets time scale
* @param timeScale * @param timeScale
*/ */
public void setTimeScale(int timeScale) { public void setTimeScale(double timeScale) {
this.timeScale = timeScale; this.timeScale = timeScale;
} }
@@ -178,7 +178,7 @@ public class Race {
*/ */
public float getDistanceTravelled(long velocity) { public float getDistanceTravelled(long velocity) {
long timeDiff = System.currentTimeMillis() - this.startTime; long timeDiff = System.currentTimeMillis() - this.startTime;
long timeElapse = timeDiff / 1000 * this.timeScale; long timeElapse = (long) (timeDiff / 1000 * this.timeScale);
return timeElapse * velocity; return timeElapse * velocity;
} }
@@ -190,7 +190,7 @@ public class Race {
// iterates all events. ends when no event in events. // iterates all events. ends when no event in events.
while (!events.isEmpty()) { while (!events.isEmpty()) {
Event peekEvent = events.peek(); 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()) { if (currentTime > peekEvent.getTime()) {
// pull out the event // pull out the event