Package com.csse3200.game.services
Class DayNightService
java.lang.Object
com.csse3200.game.services.DayNightService
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 Summary
FieldsModifier and TypeFieldDescriptionlong
long
long
long
static final int
long
long
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new DayNightService.DayNightService
(EventHandler enddayEventHandler) Constructs a new DayNightService with a provided event handler.DayNightService
(EventHandler enddayEventHandler, EventHandler docketServiceEventHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Sets up listeners for end-of-day events and high-quality meal events.int
getDay()
Gets the current day in the game.boolean
Checks if the end-of-day event has been triggered.Gets the event handler for the end-of-day events.int
Gets the number of high-quality meals served during the day.void
Increments the count of high-quality meals served.void
setDay
(int day) Sets the current day in the game.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.void
Updates the state after a second passes, resetting the flag for tracking time.
-
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
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
-
-
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
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
-