Skip to content

Instantly share code, notes, and snippets.

@jimmed
Last active August 10, 2020 14:40
Show Gist options
  • Save jimmed/203b5042c80f275cdb6d5d90af802ec9 to your computer and use it in GitHub Desktop.
Save jimmed/203b5042c80f275cdb6d5d90af802ec9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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