Академический Документы
Профессиональный Документы
Культура Документы
InitializeGameplayServiceSM
Takes a priority number, returns true
End of InitializeGameplayService
GetCurrentButtonStates
Takes no inputs, returns ReturnVal
Local variables: ReturnVal, Button2, Button1, C_bits
End of GetCurrentButtonStates
CheckButtonEvents
Takes no inputs, returns ReturnValue
Local variables: ReturnValue, CurrentButtonState_Button1,
CurrentButtonState_Button2, CurrentButtonState_Button3,
CurrentButtonState_Button4, CurrentButtonStates
End of CheckButtonEvents
RunGameplayService
Takes ES_Event ThisEvent, returns ReturnEvent
EventType field is one of: ES_TIMEOUT, WELCOME_DONE,
FENCE_HIT, BUTTONPRESSED
Local variables: results, ReturnEvent, ThisEvent
Declare ReturnEvent
Set event type to ES_NO_EVENT
Initialize NextState to CurrentState
Switch CurrentState
If InitialGameState
If event type is WELCOME_DONE
Set NextState to ActiveState
Declare results with length 2
Write knob pin ADC count to results
Declare ES_Event ThisEvent
Set event type to SEED_RECEIVED
Set event parameter to results
Post this event to LEDServiceSM
Randomize LEDRowBank based on random
number generated with seed
Turn on button backlights
Break
If ActiveState
If event type is FENCE_HIT AND event parameter is
PLAYER_FINISH_LINE OR event parameter is
OPPONENT_FINISH_LINE OR event type is
ES_TIMEOUT AND event parameter is
GAME_TIMER
Turn off button backlights
If AnyButtonsPressed is false
Set LastButtonState_Button1 to 0
Set LastButtonState_Button2 to 0
Set LastButtonState_Button3 to 0
Set LastButtonState_Button4 to 0
Set LastButtonStates to 0
Set FirstButton to 0
Set SecondButton to 0
Set ThirdButton to 0
Set FourthButton to 0
Set ButtonPattern to 0
Set MapCounter to 0
Set NumTimeouts to 0
Set NumLEDsOn to 0
Set NextState to InitialGameState
Declare ES_Event ThisEvent
Set event type to USER_DEPARTED
Post this event to Dist. List #3
Else
Set NextState to FinishedGameState
If event type is FENCE_HIT AND event
parameter is PLAYER_FINISH_LINE
Turn on next map LED
If event type is BUTTONPRESSED
If event parameter is 1
Set FirstButton to 1
If event parameter is 2
Set SecondButton to 1
If event parameter is 3
Set ThirdButton to 1
If event parameter is 4
Set FourthButton to 1
If event type is ES_TIMEOUT AND event parameter
is ROW_TIMER
Set CurrentBStates to return value of
GetCurrentButtonStates()
Increment NumTimeouts by 1
Set ButtonPattern using FirstButton,
SecondButton, ThirdButton, FourthButton, and
bitwise operations
If ButtonPattern is not 0
Set AnyButtonsPressed to true
Set ButtonPattern to ButtonPattern OR
CurrentBStates
If ButtonPattern matches appropriate element
in LEDRowBank AND NumTimeouts has
an appropriate value
Drive player motor forward
Increment MapCounter by 1
If MapCounter is at its maximum value
AND NumLEDsOn is less than 6
Light up next map LED
Increment NumLEDsOn by 1
Set MapCounter to 0
Else
Drive buzz motors based on
ButtonPattern
Set ButtonPattern to 0
Set FirstButton to 0
Set SecondButton to 0
Set ThirdButton to 0
Set FourthButton to 0
Break
If FinishedGameState
If event type is FENCE_HIT AND event parameter is
FLAG_START_POSITION
Set LastButtonState_Button1 to 0
Set LastButtonState_Button2 to 0
Set LastButtonState_Button3 to 0
Set LastButtonState_Button4 to 0
Set LastButtonStates to 0
Set FirstButton to 0
Set SecondButton to 0
Set ThirdButton to 0
Set FourthButton to 0
Set ButtonPattern to 0
Set MapCounter to 0
Set NumTimeouts to 0
Set NumLEDsOn to 0
Set NextState to InitialGameState
End of RunGameplayService
End of GameplayService