Class TimeStateMachine
Simple StateMachine that is meant to be extended or decorated to achieve state dependent behavior where every state has a fixed duration.
The method logicLoop()
must be periodically called to be able to let
the States
check for its time to be up. For this cause, the
State
must supply a State.getTimerTime()
as well as a
State.getNextState()
.
- Author:
- Angelo Aracri
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected State
TheState
, theTimeStateMachine
is currently in. -
Constructor Summary
ConstructorsConstructorDescriptionTimeStateMachine
(State initialState) The constructor that initializes theTimeStateMachine
with a giveninitialState
. -
Method Summary
Modifier and TypeMethodDescriptiongetState()
Getter for theState
theTimeStateMachine
is currently the in.void
Method that must be periodically called in order to check for theStates
time to be up.void
Switches theState
to the next as specified byState.getNextState()
.protected void
More specific version ofnextState()
that enables for switching to a givenState
that must not necessarily be specified by the currentStates
State.getNextState()
or that can be used to alter theStates
before entering them..
-
Field Details
-
currentState
TheState
, theTimeStateMachine
is currently in.
-
-
Constructor Details
-
TimeStateMachine
The constructor that initializes theTimeStateMachine
with a giveninitialState
.- Parameters:
initialState
- the initialState
.
-
-
Method Details
-
logicLoop
public void logicLoop()Method that must be periodically called in order to check for theStates
time to be up. -
nextState
public void nextState()Switches the
State
to the next as specified byState.getNextState()
.Calls both the old
States
State.leave()
as well as the new onesState.enter(TimeStateMachine parent)
. -
nextState
More specific version of
nextState()
that enables for switching to a givenState
that must not necessarily be specified by the currentStates
State.getNextState()
or that can be used to alter theStates
before entering them..- Parameters:
nextState
- the newState
to enter.
-
getState
Getter for theState
theTimeStateMachine
is currently the in.- Returns:
- the current
State
.
-