Gamesm
Gamesm
GAME_STATE_MACHINE
This state machine incorporates part of the game except the scoring
States:
PseudoState_Game
Uninitialized
SelectingPipe
WaterFlowing
IRRead
WaitforReset
*/
InitGameSM
Parameters
uint8_t : the priorty of this service
Returns
bool, false if error in initialization, true otherwise
Description
Saves away the priority, and does any
other required initialization for this service
Notes
Function
Post ES_INIT to this state machine. Return true if successful, false in case of
any error.
PostGameSM
Parameters
ES_Event_t ThisEvent ,the event to post to the queue
Returns
bool false if the Enqueue operation failed, true otherwise
Description
Posts an event to this state machine's queue
Function:
Call ES_PostToService passing the priority through MyPriority and the assigned
event
RunGameSM
Parameters
ES_Event_t : the event from its service queue to process in this State
Machine
Types of ES_Event_t:
Returns
ES_Event_t, ES_NO_EVENT if no error ES_ERROR otherwise
Description
Runs InGame state machine
Function
Switch CurrentState
If PseudoState_Game:
If event ES_INIT:
Put current state to Uninitialized_Game
If Uninitialized_Game:
If event START_GAME:
Post ACTIVATE_RANDOM_PIPE to self
Start a short timer for frequent scoring
Set the pipe timer based on the received difficulty from the
ControlSM
passed as a parameter to the START_GAME event
Initialize the random_pipe_index
Put current State to SelectingPipe
If SelectingPipe:
If event ACTIVATE_RANDOM_PIPE:
Select a random pipe among the pipes
Restart the pipe timer
Restart the score timer
Start Pipe Lights for the selected pipe
Put CurrentState to WaterFlowing
If event MARIO_END:
Switch off Pipe LEDs
Put current state to WaitForReset
If event is MARIO_END:
Switch off all LEDs
Put current state to WaitForReset
If IRRead:
If event is MARIO_END
Turn off all pipe LEDs
Put current state to WaitForReset
If event is SCORE_CHECK
If there is still an IR Connection for the active pipe:
Post SCORE_DEC to Scoring SM
Restart score timer
Put current state to WaterFlowing
Play bad action sound
If WaitForReset:
If event is Reset (either LEAF_RESET or INACTIVE_RESET):
Turn off LEDs for all the pipes
Put current state to Uninitialized_Game
return ReturnEvent