Académique Documents
Professionnel Documents
Culture Documents
Pseudo-code for the Game module (a service that implements a state machine)
InitializeGame
Takes a priority number, returns True.
CurrentState is NotPlaying
If ThisEvent is ES_NEW_PICTURE
If ThisEvent Parameter is Trash
Set NextState to Trash
Else If ThisEvent Parameter is Compost
Set NextState to Compost
Else If ThisEvent Parameter is Recycling
Set NextState to Recycling
EndIf
EndIf
End NotPlaying block
CurrentState is TrashState
If ThisEvent is ES_TIMEOUT and EventParam is WHEEL_PAUSE_TIMER
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_TRASH_BUTTON
Post ES_CORRECT_ANSWER to Sound service
Post CORRECT_ANSWER_LIGHT_TYPE with parameter
CORRECT_ANSWER_LIGHT_COLOR to LEDStrip service
Set NextState to WaitingForPic
EndIf
If ThisEvent is ES_COMPOST_BUTTON
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_RECYCLING_BUTTON
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_MULTIPLE_DOWN
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_NEED_EVE
Set NextState to WaitingForPic
EndIf
End TrashState block
CurrentState is CompostState
If ThisEvent is ES_TIMEOUT and EventParam is WHEEL_PAUSE_TIMER
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_COMPOST_BUTTON
Post ES_CORRECT_ANSWER to Sound service
Post CORRECT_ANSWER_LIGHT_TYPE with parameter
CORRECT_ANSWER_LIGHT_COLOR to LEDStrip service
Set NextState to WaitingForPic
EndIf
If ThisEvent is ES_TRASH_BUTTON
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_RECYCLING_BUTTON
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_NEED_EVE
Set NextState to WaitingForPic
EndIf
End CompostState block
CurrentState is RecyclingState
If ThisEvent is ES_TIMEOUT and EventParam is WHEEL_PAUSE_TIMER
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_RECYCLING_BUTTON
Post ES_CORRECT_ANSWER to Sound service
Post CORRECT_ANSWER_LIGHT_TYPE with parameter
CORRECT_ANSWER_LIGHT_COLOR to LEDStrip service
Set NextState to WaitingForPic
EndIf
If ThisEvent is ES_COMPOST_BUTTON
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_TRASH_BUTTON
Post ES_INCORRECT_ANSWER to Sound and LEDStrip services
Start INCORRECT_TIMER for INCORRECT_TIME
Set NextState to WrongEvent
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_NEED_EVE
Set NextState to WaitingForPic
EndIf
End RecyclingState block
CurrentState is WrongEvent
If ThisEvent is ES_TIMEOUT and EventParam is INCORRECT_TIMER
Post to LEDStrip service RESUMING_FROM_TIMEOUT_LIGHT_TYPE with
EventParam RESUMING_FROM_TIMEOUT_LIGHT_COLOR
Set NextState to WaitingForPic
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to NotPlaying
EndIf
End WrongEvent block
CurrentState is WaitingForPic
If ThisEvent is ES_NEW_PICTURE
If EveState is not HeartOn
If EventParam is Trash
Set NextState to TrashState
EndIf
If EventParam is Compost
Set NextState to CompostState
EndIf
If EventParam is Recycling
Set NextState to RecyclingState
EndIf
EndIf
EndIf
If ThisEvent is ES_GAME_LOST
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_GAME_WON
Set NextState to NotPlaying
EndIf
If ThisEvent is ES_RESET_BUTTON
Set NextState to NotPlaying
EndIf
End WaitingForPic block
Return ReturnEvent
End of GameSM