Last active
August 10, 2020 14:40
-
-
Save jimmed/203b5042c80f275cdb6d5d90af802ec9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const gameMachine = Machine({ | |
id: 'game', | |
initial: 'awaitingPlayers', | |
context: { | |
players: {} | |
}, | |
states: { | |
awaitingPlayers: { | |
on: { | |
PLAYER_JOIN: 'awaitingPlayers', | |
PLAYER_LEAVE: 'awaitingPlayers', | |
PLAYER_READY: [ | |
{ target: 'roundPlaying', cond: 'allPlayersReady' }, | |
{ target: 'awaitingPlayers' } | |
], | |
PLAYER_UNREADY: 'awaitingPlayers' | |
} | |
}, | |
roundPlaying: { | |
on: { | |
PLAYER_KILLED: [ | |
{ target: 'roundEnded', cond: 'winConditionMet' }, | |
{ target: 'roundPlaying' } | |
] | |
} | |
}, | |
roundEnded: { | |
on: { | |
GAME_RESET: 'awaitingPlayers' | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment