You are on page 1of 2

Pseudo-code for the Recipe module (a service)

Data private to the module: MyPriority, ShaqRecipe[], CurryRecipe[],


Recipes[], NumRecipeCommands[], CurrentRecipe, RecipeIndex,
RecipeCommandIndex, LastRecipeCommandIndex, GameTimerNum,
CurrentState

Functions private to the module: None

InitRecipeService
Takes a priority number, returns True.

Post Event ES_Init to this service

Set CurrentState to InitP

End of InitRecipeService

PostRecipeService
Takes an ES_Event_t, returns boolean outcome of ES_PostToService

Call ES_PostToService with MyPriority and ThisEvent

End of PostRecipeService

RunRecipeService
The EventType field of ThisEvent will be one of: ES_INIT,
BUTTON2_PRESS, ES_TIMEOUT, RECIPE_TAKE_NEXT_STEP,
RECIPE_STEP_COMPLETE

Set ReturnEvent to ES_NO_EVENT

CurrentState is:
InitP
Set CurrentState to RecipeSelection

RecipeSelection
ThisEvent is BUTTON2_PRESS
Set RecipeIndex to CURRY_RECIPE_INDEX
Set CurrentRecipe to Recipes[RecipeIndex]
Initialize RecipeCommandIndex to 0

Set CurrentState to TakeRecipeStep


Self post event RECIPE_TAKE_NEXT_STEP
Start the game timer

TakeRecipeStep
ThisEvent is ES_TIMEOUT
if GAME_TIMER_COUNT <= GameTimerNum
Post GAME_ENDED to MasterSM
Set CurrentState to RecipeSelection
else
Restart GAME_TIMER

ThisEvent is RECIPE_TAKE_NEXT_STEP
Post to MasterSM next recipe step
(CurrentRecipe[RecipeCommandIndex])
Increment RecipeCommandIndex
Set CurrentState to ExecutingRecipeStep

ExecutingRecipeStep
ThisEvent is RECIPE_STEP_COMPLETE
If RecipeCommandIndex is same as max steps in that recipe
Set CurrentState to RecipeSelection
else
Post to self RECIPE_TAKE_NEXT_STEP to start next step
Set CurrentState to TakeRecipeStep

ThisEvent is ES_TIMEOUT

ThisEvent is ES_TIMEOUT
if GAME_TIMER_COUNT <= GameTimerNum
Post GAME_ENDED to MasterSM
Set CurrentState to RecipeSelection
else
Restart GAME_TIMER

Return ES_NO_EVENT
End of RunRecipeService

You might also like