Class DayNightService

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

public class DayNightService extends Object
The DayNightService class manages the day-night cycle within the game. It tracks game time, handles day transitions, and triggers events at specific intervals, such as the end of a day or when a meal of high quality is made. It also manages bonuses given to the player for high-quality meals.
  • Field Details

    • FIVE_MINUTES

      public long FIVE_MINUTES
    • MAX_DAYS

      public static final int MAX_DAYS
      See Also:
    • SEVENTY_FIVE_PERCENT

      public long SEVENTY_FIVE_PERCENT
    • lastSecondCheck

      public long lastSecondCheck
    • lastUpgradeCheck

      public long lastUpgradeCheck
    • lastEndOfDayCheck

      public long lastEndOfDayCheck
    • timeRemaining

      public long timeRemaining
  • Constructor Details

    • DayNightService

      public DayNightService()
      Constructs a new DayNightService. Initializes the game time and event handlers. This constructor sets the first day of the game and sets up event tracking.
    • DayNightService

      public DayNightService(EventHandler enddayEventHandler)
      Constructs a new DayNightService with a provided event handler. This constructor is typically used for testing or more controlled event management.
      Parameters:
      enddayEventHandler - Event handler to manage the end-of-day events
    • DayNightService

      public DayNightService(EventHandler enddayEventHandler, EventHandler docketServiceEventHandler)
  • Method Details

    • create

      public void create()
      Sets up listeners for end-of-day events and high-quality meal events. This method initializes listeners for in-game decisions and meal-related events.
    • incrementHighQualityMealCount

      public void incrementHighQualityMealCount()
      Increments the count of high-quality meals served. This method is triggered when a "mealHighQuality" event occurs.
    • update

      public void update()
      Updates the game state, tracking elapsed time and checking whether it is time to trigger end-of-day events or other timed events such as upgrades.
    • getDay

      public int getDay()
      Gets the current day in the game.
      Returns:
      the current day number
    • setDay

      public void setDay(int day)
      Sets the current day in the game.
      Parameters:
      day - the day to set as the current day
    • getEvents

      public EventHandler getEvents()
      Gets the event handler for the end-of-day events.
      Returns:
      the event handler for end-of-day events
    • getEndOfDayTriggered

      public boolean getEndOfDayTriggered()
      Checks if the end-of-day event has been triggered.
      Returns:
      true if the end-of-day event was triggered, false otherwise
    • updatepastSecond

      public void updatepastSecond()
      Updates the state after a second passes, resetting the flag for tracking time.
    • getHighQualityMeals

      public int getHighQualityMeals()
      Gets the number of high-quality meals served during the day.
      Returns:
      the number of high-quality meals