# Class HourGlass

java.lang.Object
it.polimi.ingsw.is25am31.controller.HourGlass

All Implemented Interfaces:
  `Serializable`

public class HourGlass extends Object implements Serializable
Represents a countdown timer with a default duration of 90 seconds. The timer can be started, stopped, and queried for its current state.

See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HourGlass()`
  Constructs a new HourGlass with default settings.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getSecondsLeft()`
  Returns the number of seconds remaining in the countdown.
  `boolean`
  `isRunning()`
  Checks whether the countdown timer is currently running.
  `void`
  `start()`
  Starts the countdown timer if it's not already running.
  `void`
  `stop()`
  Stops the countdown timer and shuts down the scheduler.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### HourGlass

    public HourGlass()
    Constructs a new HourGlass with default settings. Initializes the scheduler with a single thread pool and sets the timer to not running. The initial countdown value is set to 90 seconds.

- ## Method Details

  - ### start

    public void start()
    Starts the countdown timer if it's not already running. The timer decrements every second and automatically stops and resets when reaching zero. If the scheduler is shutdown or null, it will be recreated before starting.

    If the timer is already running, this method has no effect.

    The countdown task runs at a fixed rate of 1 second intervals, decrementing the seconds counter until it reaches zero, at which point the timer stops and resets to 90 seconds.

  - ### stop

    public void stop()
    Stops the countdown timer and shuts down the scheduler. If the timer is currently running, it will be stopped and the running state set to false. The scheduler service is forcefully shut down, terminating any ongoing tasks.

    After calling this method, the HourGlass instance should not be reused unless a new scheduler is created (which happens automatically in the start() method).

  - ### getSecondsLeft

    public int getSecondsLeft()
    Returns the number of seconds remaining in the countdown.
    Returns:
      the current number of seconds left in the timer (0-90)

  - ### isRunning

    public boolean isRunning()
    Checks whether the countdown timer is currently running.
    Returns:
      true if the timer is currently counting down, false otherwise