Package com.csse3200.game.services
Class CountdownTimerService
java.lang.Object
com.csse3200.game.services.CountdownTimerService
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 Summary
ConstructorsConstructorDescriptionCountdownTimerService
(GameTime gameTime, long durationMS) Creates a new countdown timer -
Method Summary
Modifier and TypeMethodDescriptionlong
Get the total duration of the countdown timerlong
Gets the remaining time in msboolean
isPaused()
Checks if the timer is currently pausedboolean
isTimeUP()
Checks whether the countdown is finishedvoid
pause()
Pause the countdown timer.void
resume()
Resume the counter timer if it was paused
-
Constructor Details
-
CountdownTimerService
Creates a new countdown timer- Parameters:
gameTime
- theGameTime
for tracking timedurationMS
- the duration of the countdown in ms
-
-
Method Details
-
getRemainingMs
public long getRemainingMs()Gets the remaining time in msIf 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 pausedIf 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
-