Class TimeService

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

public class TimeService extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a basic TimeService instance to track the in-game time
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the current in-game day
    Gets the event handler for the TimeService
    int
    Gets the current in-game hour
    int
    Gets the current in-game minute
    boolean
    Determines whether it is day or not
    boolean
    Determines whether it is night or not
    boolean
    Returns whether the game is paused or not
    void
    loadTime(int day, int hour, int minute)
     
    void
    setDay(int day)
    Sets the in-game day to a certain value.
    void
    setHour(int hour)
    Sets the in-game hour to a certain value.
    void
    setMinute(int minute)
    Sets the in-game minute to a certain value.
    void
    setNearestTime(int hour)
    Sets the in-game hour to the nearest future hour passed in, rounded to 0 minutes.
    void
    setNearestTime(int hour, int minute)
    Sets the in-game hour and minute to the nearest future value passed in.
    void
    setPaused(boolean state)
    Changes the pause state of the game
    void
    Tracks the in-game time stored in the time service.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TimeService

      public TimeService()
      Constructs a basic TimeService instance to track the in-game time
  • Method Details

    • isPaused

      public boolean isPaused()
      Returns whether the game is paused or not
      Returns:
      boolean value representing whether the game is paused or not
    • setPaused

      public void setPaused(boolean state)
      Changes the pause state of the game
      Parameters:
      state - boolean value for whether the game is paused or not
    • getHour

      public int getHour()
      Gets the current in-game hour
      Returns:
      in-game hour
    • setHour

      public void setHour(int hour)
      Sets the in-game hour to a certain value. Also updates the time buffer and triggers any necessary events
      Parameters:
      hour - in-game hour
    • getDay

      public int getDay()
      Gets the current in-game day
      Returns:
      in-game day
    • getMinute

      public int getMinute()
      Gets the current in-game minute
      Returns:
      in-game minute
    • setMinute

      public void setMinute(int minute)
      Sets the in-game minute to a certain value. Also updates the time buffer and triggers any necessary events
      Parameters:
      minute - in-game minute
    • isDay

      public boolean isDay()
      Determines whether it is day or not
      Returns:
      whether it is day or not
    • setDay

      public void setDay(int day)
      Sets the in-game day to a certain value. Also updates the time buffer and triggers any necessary events
      Parameters:
      day - in-game day
    • isNight

      public boolean isNight()
      Determines whether it is night or not
      Returns:
      whether it is night or not
    • setNearestTime

      public void setNearestTime(int hour)
      Sets the in-game hour to the nearest future hour passed in, rounded to 0 minutes. Increments the day if necessary, updates the time buffer, and triggers any necessary events.
      Parameters:
      hour - in-game hour
    • setNearestTime

      public void setNearestTime(int hour, int minute)
      Sets the in-game hour and minute to the nearest future value passed in. Increments the day if necessary, updates the time buffer, and triggers any necessary events.
      Parameters:
      hour - in-game hour
      minute - in-game minute
    • getEvents

      public EventHandler getEvents()
      Gets the event handler for the TimeService
      Returns:
      event handler
    • update

      public void update()
      Tracks the in-game time stored in the time service. This method is called in the main game loop. It calculates the time that has passed since it last checked the time and calculates whether in-game time has elapsed.
    • loadTime

      public void loadTime(int day, int hour, int minute)