Anda di halaman 1dari 3

/*

SCORING_STATE_MACHINE

This state machine keeps track of the score

Data private to the module:


MyPriority

*/

Include Dependent Files


Function define module functions

Specify Module Variables


MyPriority - holds the priority for this SM
CurrentState - holds current state of this State Machine
Score - stores the current score

InitScoringSM

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

Function

Initialize the MyPriority module variable with the passed priority

Set current state of this state machine as pseudo state

Post ES_INIT to this state machine. Return true if successful, false in case of
any error.

PostScoringSM

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

RunScoringSM

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
Notes

Function

Declare a ReturnEvent and initialise it as ES_NO_EVENT. This would be returned


in case of no error.

Switch CurrentState
If PseudoState_Scoring:
Put the current state to Uninitialized_Scoring

If Uninitialized_Scoring:
If event is START_GAME):
Switch on the green led
Initiailize the module variable score to a start score
Put current state to GreenLED

If GreenLed:
If event is SCORE_DEC:
Decrease score by a point
If score remains greater than or equal to the first score
threshold:
Remain in the GreenLED state
Else:
Switch on the yellow LED
Change current state to GreenAndYellowLED

If event is LEAF_RESET or INACTIVE_RESET:


put current state to Uninitialized_Scoring

If event is MARIO_END:
play a good sound
put current state to WaitForEnding

If GreenAndYellowLED:
If event is SCORE_DEC:
Decrease score by a point
If score remains greater than or equal to the second score
threshold:
Remain in the GreenAndYellowLED state
Else:
Switch off the green LED
Change current state to YellowLED

If event is LEAF_RESET or INACTIVE_RESET:


put current state to Uninitialized_Scoring

If event is MARIO_END:
play a good sound
put current state to WaitForEnding

If YellowLED:
If event is SCORE_DEC:
Decrease score by a point
If score remains greater than or equal to the third score
threshold:
Remain in the YellowLED state
Else:
Switch on the red LED
Change current state to YellowAndRedLED

If event is LEAF_RESET or INACTIVE_RESET:


put current state to Uninitialized_Scoring

If event is MARIO_END:
play a sow-sow sound
put current state to WaitForEnding

If YellowAndRedLED:
If event is SCORE_DEC:
Decrease score by a point
If score remains greater than or equal to the fourth score
threshold:
Remain in the YellowAndRedLED state
Else:
Switch off the yellow LED
Change current state to RedLED

If event is LEAF_RESET or INACTIVE_RESET:


put current state to Uninitialized_Scoring

If event is MARIO_END:
play a sow-sow sound
put current state to WaitForEnding

If RedLED:
If event is SCORE_DEC:
Decrease score by a point if score is greater than zero
Remain in the RedLED state

If event is LEAF_RESET or INACTIVE_RESET:


put current state to Uninitialized_Scoring

If event is MARIO_END:
play a bad sound
put current state to WaitForEnding

If WaitForEnding:
If event is FLAG_UP:
put current state as Uninitialized_Scoring

If event is LEAF_RESET or INACTIVE_RESET:


put current state to Uninitialized_Scoring

return ReturnEvent

Anda mungkin juga menyukai