From 3eb6ed4ff38166ec9745488482a6bbb301fcfbfb Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sat, 3 Dec 2016 17:27:03 +0100 Subject: [PATCH] Fixed #48 --- src/de/bricked/ui/LevelController.java | 15 ++++++++- src/de/bricked/utils/CountdownTimer.java | 39 ++++++++++++++---------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/de/bricked/ui/LevelController.java b/src/de/bricked/ui/LevelController.java index a5cf496..c112bb5 100644 --- a/src/de/bricked/ui/LevelController.java +++ b/src/de/bricked/ui/LevelController.java @@ -561,7 +561,13 @@ public class LevelController labelPause.setTranslateX(((gamePaneWidth - t.getLayoutBounds().getWidth() + 10) / 2) + 22); labelPause.setTranslateY(((gamePaneHeight - t.getLayoutBounds().getHeight()) / 2) + 125); - anchorPane.getChildren().add(labelPause); + anchorPane.getChildren().add(labelPause); + + //pause all timedPowerUps + for(CountdownTimer currentTimer : timedPowerUps) + { + currentTimer.stop(); + } } private void restart() @@ -571,6 +577,13 @@ public class LevelController fps = 0; anchorPaneGame.setOpacity(1.0); anchorPane.getChildren().remove(anchorPane.getChildren().size() - 1); + + //restart all timedPowerUps + for(CountdownTimer currentTimer : timedPowerUps) + { + currentTimer.start(); + } + timer.start(); } diff --git a/src/de/bricked/utils/CountdownTimer.java b/src/de/bricked/utils/CountdownTimer.java index 84cb3ac..6f148ce 100644 --- a/src/de/bricked/utils/CountdownTimer.java +++ b/src/de/bricked/utils/CountdownTimer.java @@ -12,17 +12,33 @@ public class CountdownTimer { private int count; private HBox hbox; + private LevelController levelController; private Timer timer; + private TimerTask task; + private CountdownTimer self; public CountdownTimer(int seconds, HBox hbox, LevelController levelController) { this.count = seconds; - this.hbox = hbox; + this.hbox = hbox; + self = this; - CountdownTimer self = this; - - timer = new Timer(); - TimerTask task = new TimerTask() + start(); + } + + public void addSecondsToTimer(int seconds) + { + this.count += seconds; + } + + public HBox getHBox() + { + return hbox; + } + + public void start() + { + task = new TimerTask() { @Override public void run() @@ -52,22 +68,13 @@ public class CountdownTimer } } }; + timer = new Timer(); timer.schedule(task, 0, 1000); } - public void addSecondsToTimer(int seconds) - { - this.count += seconds; - } - - public HBox getHBox() - { - return hbox; - } - public void stop() { - timer.cancel(); + timer.cancel(); timer.purge(); } } \ No newline at end of file -- GitLab