From cc824aa89a3784a6f6d34e23bdba90205fddb14d Mon Sep 17 00:00:00 2001 From: cbt24 Date: Sat, 6 May 2017 18:20:41 +1200 Subject: [PATCH] Removed unnecessary countdownTimer from Race in visualiser module - Run method now calls simulateRace directly #story[782] --- .../src/main/java/seng302/Model/Race.java | 81 +------------------ 1 file changed, 1 insertion(+), 80 deletions(-) diff --git a/visualiser/src/main/java/seng302/Model/Race.java b/visualiser/src/main/java/seng302/Model/Race.java index b3085432..7ea0edcb 100644 --- a/visualiser/src/main/java/seng302/Model/Race.java +++ b/visualiser/src/main/java/seng302/Model/Race.java @@ -21,7 +21,6 @@ import java.util.Random; * Created by fwy13 on 3/03/17. */ public abstract class Race implements Runnable { - //protected Boat[] startingBoats; protected ObservableList startingBoats; protected List legs; protected RaceController controller; @@ -30,8 +29,6 @@ public abstract class Race implements Runnable { protected int scaleFactor; private int lastFPS = 20; - private int PRERACE_TIME = 0; //time in milliseconds to pause during pre-race - private boolean timerEnabled = true; //boolean to determine if timer is ran /** * Initailiser for Race @@ -103,81 +100,7 @@ public abstract class Race implements Runnable { public void run() { setControllerListeners(); initialiseBoats(); - if (timerEnabled) countdownTimer(); - //simulateRace(); - } - - /** - * Disable the timer - */ - public void disableTimer() { - timerEnabled = false; - } - - - /** - * Countdown timer until race starts. Use PRERACE_TIME to set countdown duration. - */ - protected void countdownTimer() { - new AnimationTimer() { - long currentTime = System.currentTimeMillis(); - long startTime = currentTime + (PRERACE_TIME/scaleFactor); - long minutes; - long currentTimeInSeconds; - long remainingSeconds; - long hours; - long timeLeft; - - @Override - public void handle(long arg0) { - timeLeft = startTime - currentTime; - if (timeLeft <= 0 && controller != null) { - updateTime("Race is starting..."); - stop(); - simulateRace(); - } else { - currentTimeInSeconds = (timeLeft*scaleFactor) / 1000; - minutes = currentTimeInSeconds / 60; - remainingSeconds = currentTimeInSeconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - if (controller != null) { - updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds)); - } - } - currentTime = System.currentTimeMillis(); - } - }.start(); - } - - /** - * Takes total time elapsed and format to hour:minute:second - * - * @return Formatted time as string - */ - protected String calcTimer() { - long minutes; - long currentTimeInSeconds; - long remainingSeconds; - long hours; - - currentTimeInSeconds = (totalTimeElapsed * scaleFactor) / 1000; - minutes = currentTimeInSeconds / 60; - remainingSeconds = currentTimeInSeconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds); - } - - /** - * Updates the calculated time to the timer label - * - * @param time The calculated time from calcTimer() method - */ - protected void updateTime(String time) { - Platform.runLater(() -> { - controller.setTimer(time); - }); + simulateRace(); } /** @@ -222,8 +145,6 @@ public abstract class Race implements Runnable { boat.addTrackPoint(boat.getCurrentPosition()); } } - if (timerEnabled) - updateTime(calcTimer()); } controller.updateMap(startingBoats); fps++;