Package com.csse3200.game.components
Class ButtonManagerComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.ButtonManagerComponent
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
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddButton(ButtonComponent button) Adds a button to the list of buttons managed by this managervoiddispose()Called when the component is disposed.Returns list of buttons being managed by this puzzle button managerfloatGets time remaining before puzzle fails i.e.booleanChecks if puzzle successfully completedvoidCalled when any button is pressed, starts the timer if the puzzle isn't already activevoidResets puzzle state by clearing progress, deactivating puzzle and unpressing all buttons being controlled by the managervoidupdate()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()Methods inherited from class com.csse3200.game.components.Component
create, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
ButtonManagerComponent
public ButtonManagerComponent()
-
-
Method Details
-
addButton
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() -
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
Returns list of buttons being managed by this puzzle button manager- Returns:
- list of ButtonComponents being managed
-
dispose
public void dispose()Description copied from class:ComponentCalled when the component is disposed. Dispose of any internal resources here.
-