Class ItemTimerComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.items.ItemTimerComponent
Direct Known Subclasses:
ChopIngredientComponent, CookIngredientComponent

public abstract class ItemTimerComponent extends Component
TimerComponent.java Timer component used for item cooking and chopping. Able to be set with a time started, stopped, and paused etc. This will modify the current impletmentation of item cooking
  • Field Details

    • gameTime

      protected final GameTime gameTime
      Class member variables. - gameTime the global gametime service - length finishing time of the timer - elapsed the current ammount of time elapsed - isRunning if the timer is running starts as false when item created - multiplier the current multiplier of the station if cooking
    • length

      protected long length
    • elapsed

      protected long elapsed
    • isRunning

      protected boolean isRunning
  • Constructor Details

    • ItemTimerComponent

      public ItemTimerComponent()
      TimerComponent initialiser creates a timer which has the legnth set to Float.MAX_VALUE, the time length must be set manually. This is so that timings depending on upgrades and such are not prevented in the future.
  • Method Details

    • update

      public void update()
      Function to run each frame
      Overrides:
      update in class Component
    • setLength

      protected void setLength(long length)
      Set the length of the timer. This should be used before the timer has started running, but is not prevented from being used while it is running however, if used the completion status of the timer could change.
      Parameters:
      length - of time the timer should run for requires length > 0
    • startTimer

      protected void startTimer()
      Sets the timer to start running.
    • stopTimer

      protected void stopTimer()
      Set the timer to stop running.
    • isFinished

      protected boolean isFinished()
      Determines if the timer is finished.
      Returns:
      true if the time elapsed is greater than the length, false otherwise
    • getCompletionPercent

      public float getCompletionPercent()
      Gets the percentage completion of the timer. e.g. if the length is 10s and 3s has passed 30f will be returned.
      Returns:
      The percentage completion of the timer.
    • updateItem

      protected abstract void updateItem()
      Method to update an item to a new state depending on the item type. Abtract since cooking and chopping will have different implementations.
    • rageModeOn

      protected void rageModeOn()
      Method to call when rage mode is activated by the user. Reduces the time that the item will take to cook
    • rageModeOff

      protected void rageModeOff()
      Method to call when rage mode is deactivated by the user. Changes back the time that the item takes to cook back to normal.