0% found this document useful (0 votes)
384 views5 pages

Gameplaytoplevelsm Pseudocode

Uploaded by

api-581263110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
384 views5 pages

Gameplaytoplevelsm Pseudocode

Uploaded by

api-581263110
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Pseudo-code for the GameplayTopLevelSM module (a service that

implements a hierarchical state machine)


Data private to the module: CurrentState

Functions private to the module: DuringWaiting, DuringStarting,


DuringPreparing, DuringExecuting, EndGame

RunGameplayTopLevelSM (implements a state machine)


The EventType field of ThisEvent will be one of: START_STARTING,
START_PREPARING, START_EXECUTING, STOP_STARTING, STOP_PREPARING,
STOP_EXECUTING, GAME_ENDED

Data private to the function: MakeTransition, NextState,


CurrentState, EntryEventKind, ReturnEvent

Based on the state of the CurrentState variable choose one of the


following blocks of code:

CurrentState is Waiting
Set ReturnEvent equal to CurrentEvent equal to return of
DuringWaiting()
If CurrentEvent.EventType is not equal to ES_NO_EVENT
ThisEvent is START_STARTING
Set NextState equal to Starting
Set MakeTransition equal to true
ThisEvent is START_PREPARING
Set NextState equal to Starting
Set MakeTransition equal to true
ThisEvent is START_EXECUTING
Set NextState equal to Starting
Set MakeTransition equal to true
EndIf
End Waiting block

CurrentState is Starting
Set ReturnEvent equal to CurrentEvent equal to return of
DuringStarting()
If CurrentEvent.EventType is not equal to ES_NO_EVENT
ThisEvent is STOP_STARTING
Set NextState equal to Waiting
Set MakeTransition equal to true
ThisEvent is GAME_ENDED
Set NextState equal to Waiting
Set MakeTransition equal to true
Call EndGame()
EndIf
End Starting block

CurrentState is Preparing
Set ReturnEvent equal to CurrentEvent equal to return of
DuringPreparing()
If CurrentEvent.EventType is not equal to ES_NO_EVENT
ThisEvent is STOP_PREPARING
Set NextState equal to Waiting
Set MakeTransition equal to true
ThisEvent is GAME_ENDED
Set NextState equal to Waiting
Set MakeTransition equal to true
Call EndGame()
EndIf
End Preparing block

CurrentState is Executing
Set ReturnEvent equal to CurrentEvent equal to return of
DuringExecuting()
If CurrentEvent.EventType is not equal to ES_NO_EVENT
ThisEvent is STOP_EXECUTING
Set NextState equal to Waiting
Set MakeTransition equal to true
ThisEvent is GAME_ENDED
Set NextState equal to Waiting
Set MakeTransition equal to true
Call EndGame()
EndIf
End Executing block

If MakeTransition equals true


Set CurrentEvent to ES_EXIT
Call RunGameplayTopLevelSM with CurrentEvent
Set CurrentState equal to NextState
Call RunGameplayTopLevelSM with EntryEvent
EndIf

Return ReturnEvent
End of RunGameplayTopLevelSM
StartGameplayTopLevelSM
Takes CurrentEvent as parameter, returns nothing.

Set CurrentState equal to Waiting


Call RunGameplayTopLevelSM with CurrentEvent

End of StartGameplayTopLevelSM

DuringWaiting
Takes Event as parameter, returns Event.

If Event is ES_ENTRY

Endif

Else if event is ES_EXIT

Endif

Else

EndElse

Return Event

End of DuringWaiting

DuringStarting
Takes Event as parameter, returns Event.

If Event is ES_ENTRY
Call StartStartingSM with Event
Endif

Else if event is ES_EXIT


Set Event equal to return of call to RunStartingSM with
parameter Event

Post RECIPE_STEP_COMPLETE to RecipeService


Endif

Else
Set Event equal to return of call to RunStartingSM with
parameter Event
EndElse
Return Event

End of DuringStarting

DuringPreparing
Takes Event as parameter, returns Event.

If Event is ES_ENTRY
Call StartPreparingSM with Event
Endif

Else if event is ES_EXIT


Set Event equal to return of call to RunPreparingSM with
parameter Event

Post RECIPE_STEP_COMPLETE to RecipeService


Endif

Else
Set Event equal to return of call to RunPreparingSM with
parameter Event
EndElse

Return Event

End of DuringPreparing

DuringExecuting
Takes Event as parameter, returns Event.

If Event is ES_ENTRY
Call StartExecutingSM with Event
Endif

Else if event is ES_EXIT


Set Event equal to return of call to RunExecutingSM with
parameter Event

Post RECIPE_STEP_COMPLETE to RecipeService


Endif

Else
Set Event equal to return of call to RunExecutingSM with
parameter Event
EndElse

Return Event

End of DuringExecuting

EndGame

Post GAME_ENDED to SPILeaderService


Post ES_LAUNCH_OFF to SPILeaderService
Post DRIVE_STOP to MotorService

End of EndGame

You might also like