Package com.csse3200.game.services
Class TimeService
java.lang.Object
com.csse3200.game.services.TimeService
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a basic TimeService instance to track the in-game time -
Method Summary
Modifier and TypeMethodDescriptionint
getDay()
Gets the current in-game dayGets the event handler for the TimeServiceint
getHour()
Gets the current in-game hourint
Gets the current in-game minuteboolean
isDay()
Determines whether it is day or notboolean
isNight()
Determines whether it is night or notboolean
isPaused()
Returns whether the game is paused or notvoid
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 gamevoid
update()
Tracks the in-game time stored in the time service.
-
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 hourminute
- in-game minute
-
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)
-