Skip to content
Snippets Groups Projects
Select Git revision
  • d90d6a2b9504f2a7891d6e2f1b76573fbbf949b8
  • master default
  • renovate/datatables.version
  • renovate/opencsv.version
  • renovate/org.springframework.boot-spring-boot-starter-parent-3.x
  • renovate/junit-jupiter-engine.version
  • renovate/selenium.version
  • renovate/testcontainer.version
  • demo
  • v1_8_1
  • v2.18.1
  • v2.18.0
  • v2.17.2
  • v2.17.1
  • v2.17.0
  • v2.16.1
  • v2.16.0
  • v2.15.1
  • v2.15.0
  • v2.14.0
  • v2.13.0
  • v2.12.0
  • v2.11.0
  • v2.10.0
  • v2.9.2
  • v2.9.1
  • v2.9.0
  • v2.8.0
  • testPipeline2
  • v2.7.0
30 results

hotkeys.js

Blame
  • CountdownTimer.java 1.20 KiB
    package de.bricked.utils;
    
    import java.util.Timer;
    import java.util.TimerTask;
    
    import de.bricked.ui.LevelController;
    import javafx.application.Platform;
    import javafx.scene.control.Label;
    import javafx.scene.layout.HBox;
    
    public class CountdownTimer
    {
    	private int count;	
    	private HBox hbox;	
    	private Timer timer;
    
    	public CountdownTimer(int seconds, HBox hbox, LevelController levelController)
    	{
    		this.count = seconds;
    		this.hbox = hbox;
    		
    		CountdownTimer self = this;
    		
    		timer = new Timer();
    		TimerTask task = new TimerTask()
    		{
    			@Override
    			public void run()
    			{
    				Platform.runLater(()->{
    					try
    					{
    						Label labelSeconds = (Label)hbox.getChildren().get(1);
    						labelSeconds.setText(String.valueOf(count));
    					}
    					catch(Exception e)
    					{
    						
    					}
    				});			
    				if(count > 0)
    				{
    					count--;
    				}
    
    				if(count == 0)
    				{
    					Platform.runLater(()->{
    						levelController.deactivatePowerUp(self, hbox);
    					});
    					timer.cancel();
    				}				
    			}
    		};
    		timer.schedule(task, 0, 1000);
    	}
    	
    	public void addSecondsToTimer(int seconds)
    	{
    		this.count += seconds;
    	}	
    	
    	public HBox getHBox()
    	{
    		return hbox;
    	}	
    	
    	public void stop()
    	{
    		timer.cancel();
    		timer.purge();
    	}
    }