Day Night Cycle - UQcsse3200/2024-studio-3 GitHub Wiki
Introduction
The DayNightService class manages the day/night cycle in the game. It uses GameTime to track the time on a predefined variable (5 minutes) and handles the transition from day and night by triggering events, which other components respond to.
Functionality
The main functionality of this feature is to;
- Track time to the interval of 5 minutes which then triggers the end of day cycle.
- Once the end of day condition is met, the game time is paused and certain events are triggered to ultimately dispose game components, transition to the enddaydisplay then moraldecisiondisplay and finally back to the maingamescreen as a newday
- Event Handling by triggering events, allowing for other components such as displays to listen and repsond.
Key Attributes and Fields
logger (Logger)
: Used to log events and activitiesFIVE_MINUTES (long)
: Constant representing 5 minuteslastCheckTime(long)
: Stores last time check intervalgameTime (GameTime)
: checks and manipulates the time in gameendOfDayTriggered (boolean)
: flag which defines whether the end of day sequence has been triggered.enddayEventHandler (EventHandler)
: Manages events and listens to events within this cycle.
Methods
create()
: Sets up event listeners for handling the new day. Listens for "decisionDone" event.update()
: Constantly checks the game time and compares the last interval to the variable containing 5 minutes of elapsed time, triggering the end of day cycle.startNewDay()
: Starts the new day. Resumes game time and clears endOfDayTriggered flag.getEvents()
: Access to the event handler to listen and trigger events.
Events
- Dispose: Triggered during end of day sequence to inform MainGameOrderTicketDisplay to reset.
- endOfDay: Indicates end of day, related to updating necessary affected displays and transitioning to enddaydisplay then moraldecisiondisplay.
- decisionDone: Used in the
startNewDay()
method to trigger the start of a new day. - newday: Start of a new day, facilitating components to update necessary actions such as updating the current day display.
- callpastsecond: used in update as a trigger for every second in the game, to update and matc for the displayed timer
UML
![Screen Shot 2024-09-12 at 12 39 12 pm](https://github.com/user-attachments/assets/af4627ee-13bb-4573-a495-1936fa2c9772)