Class CountdownTimerService

java.lang.Object
com.csse3200.game.services.CountdownTimerService

public class CountdownTimerService extends Object
Service for managing a countdown timer in a game.

This service allows you to track elapsed time, check remaining time, pause and resume the countdown, and determine if the timer has expired.

  • Constructor Details

    • CountdownTimerService

      public CountdownTimerService(GameTime gameTime, long durationMS)
      Creates a new countdown timer
      Parameters:
      gameTime - the GameTime for tracking time
      durationMS - the duration of the countdown in ms
  • Method Details

    • getRemainingMs

      public long getRemainingMs()
      Gets the remaining time in ms

      If the timer is paused, calculates based on the paused time; otherwise calculates based on teh current game time

      Returns:
      the remaining game time in ms, minimum 0
    • isTimeUP

      public boolean isTimeUP()
      Checks whether the countdown is finished
      Returns:
      true if the timer has reached 0, false otherwise
    • pause

      public void pause()
      Pause the countdown timer.

      If the time is paused, this method does nothing

    • resume

      public void resume()
      Resume the counter timer if it was paused

      If the timer is not paused, this method does nothing

    • isPaused

      public boolean isPaused()
      Checks if the timer is currently paused
      Returns:
      true if paused, false otherwise
    • getDuration

      public long getDuration()
      Get the total duration of the countdown timer
      Returns:
      the duration in ms