A turn state machine provides a structured way to control the different stages of a turn-based multiplayer game.
Instead of allowing actions at any time, the game can move through predefined states such as waiting for a player, rolling the dice, selecting an action, processing the action, and ending the turn.
- What Is a Turn State Machine?
- Why Use a State Machine?
- Basic Turn Flow
- Turn States
- State Transition
- Example TurnState Enum
- Example Turn Manager
- Validating Player Actions
- Handling Invalid Actions
- Handling Disconnections
- Turn Timer
- Multiplayer Synchronization
- Testing the Turn State Machine
- Related Documentation
- Conclusion
A turn state machine divides gameplay into clearly defined states.
For example:
WaitingForPlayer
|
v
StartTurn
|
v
RollDice
|
v
ChooseAction
|
v
ProcessAction
|
v
EndTurn
|
v
StartTurn