GameTimerLogic.java

package io.github.some_example_name;

/**
 * <code>GameTimerLogic</code> implements core countdown logic for the game timer.
 * <p>
 * Tracks and decrements time, no LibGDX dependencies for testing timer behaviour.
 *
 * @since 2025-11-04
 */
public class GameTimerLogic {

    /** Time remaining in seconds */
    private float timeLeft;

    /**
     * Constructs a new timer logic instance with the starting time.
     *
     * @param startSeconds initial time in seconds
     */
    public GameTimerLogic(float startSeconds) {
        this.timeLeft = Math.max(0f, startSeconds);
    }

    /**
     * Decrements timer by the given value, stopping at zero.
     *
     * @param delta amount of time to subtract (seconds)
     */
    public void decrement(float delta) {
        if (delta <= 0f) {
            return;
        }

        timeLeft -= delta;
        if (timeLeft < 0f) {
            timeLeft = 0f;
        }
    }

    /**
     * Returns time remaining in seconds.
     *
     * @return time left in seconds
     */
    public float getTimeLeft() {
        return timeLeft;
    }

    /**
     * Shows whether the timer has reached zero.
     *
     * @return true if time has run out, false otherwise
     */
    public boolean isTimeUp() {
        return timeLeft <= 0f;
    }

    /**
     * Adds time to the timer (e.g. bonuses or penalties).
     *
     * @param seconds amount of time to add (can be negative)
     */
    public void addTime(float seconds) {
        timeLeft += seconds;

        if (timeLeft < 0f) {
            timeLeft = 0f;
        }
    }


}