I'm currently working on this Clash Royale style game in Java FX and I have a game timer in one class that I set in my test condition. However, when I check its value over on the GameView class it's always false. I've looked at many examples and the latest I tried making my properties static in my timer class but that didn't have any effect either. Hoping someone could steel me in the right direction. Thanks!
public class GameTimer {
public int seconds = 180;
public static boolean endGame;
public static boolean returnBool () {
return endGame;
}
public static boolean isEndGame() {
return endGame;
}
public static void setEndGame(boolean endGame) {
GameTimer.endGame = endGame;
}
Timer timer = new Timer();
TimerTask task = new TimerTask(){
public void run(){
seconds--;
System.out.println("180 / " + seconds);
if (seconds == 170){
System.out.println("170 seconds hit the spot" );
endGame = true;
this.cancel();
}
}
};
public void start(){
timer.scheduleAtFixedRate(task, 1000, 1000);
isEndGame();
}
}
public class GameViewManager {
public void gameTimer() {
GameTimer timer = new GameTimer();
timer.start();
//System.out.println(timer.returnBool());
if (timer.isEndGame()){
//gameStage.close();
System.out.println("test");
}
}
}