Class ButtonManagerComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.ButtonManagerComponent

public class ButtonManagerComponent extends Component
Manages a group of buttons that form one full button puzzle in which all buttons in manager must be pressed in a set amount of time Tracks button states, handles puzzle timing, triggers even on success and resets all buttons on failure
  • Constructor Details

    • ButtonManagerComponent

      public ButtonManagerComponent()
  • Method Details

    • addButton

      public void addButton(ButtonComponent button)
      Adds a button to the list of buttons managed by this manager
      Parameters:
      button - the ButtonComponent to add
    • onButtonPressed

      public void onButtonPressed()
      Called when any button is pressed, starts the timer if the puzzle isn't already active
    • update

      public void update()
      Updates the puzzle timer and checks button state If all buttons pressed before timer expires, puzzle completed and event triggered If time runs out before buttons all marked as pressed, all buttons are reset by forceUnpress()
      Overrides:
      update in class Component
    • isPuzzleCompleted

      public boolean isPuzzleCompleted()
      Checks if puzzle successfully completed
      Returns:
      true of puzzle completed, false otherwise
    • resetPuzzle

      public void resetPuzzle()
      Resets puzzle state by clearing progress, deactivating puzzle and unpressing all buttons being controlled by the manager
    • getTimeLeft

      public float getTimeLeft()
      Gets time remaining before puzzle fails i.e. time left to complete
      Returns:
      time left if puzzle active, 0 otherwise
    • getButtons

      public List<ButtonComponent> getButtons()
      Returns list of buttons being managed by this puzzle button manager
      Returns:
      list of ButtonComponents being managed