Finite State Machine (FSM) - DerekJi/ngtetris GitHub Wiki
Install the chrome extension Markdown Diagrams to view the
plantuml
diagrams below.
Finite State Machine
After powered on, the Tetris has 5 states
- NOT_STARTED: play the animations, and then send
SET_READY
event - READY: show the screen of READY, waiting for START event
- STARTED: game started.
- PAUSED: game paused.
- COMPLETED: game over. It plays the animations, and then sends
RESET
event to transit toNOT_STARTED
state
@startuml
[*] -[#blue,bold]-> NOT_STARTED
NOT_STARTED -left-> NOT_STARTED: Tick
NOT_STARTED -[#blue,bold]-> READY: SetReady
READY -[#blue,bold]down-> STARTED: Start/Pause
STARTED -[#gray]-> PAUSED: Start/Pause
PAUSED -[#gray]-> STARTED: Start/Pause
STARTED -[#blue,bold]-> COMPLETE: Down/Tick/Drop
STARTED -up-> STARTED: LEFT, RIGHT, ROTATE, DOWN, DROP, Tick
STARTED -[#DD33AA]left-> NOT_STARTED: Reset
PAUSED -[#DD33AA]-> NOT_STARTED: Reset
COMPLETE -[#DD33AA]-> NOT_STARTED: Reset
COMPLETE -[#blue,bold]left-> [*]
COMPLETE: Game over
@enduml