Skip to content

Instantly share code, notes, and snippets.

@netpoetica
Created November 29, 2020 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netpoetica/70eae880cc0e152d499dcfad5e82ea8a to your computer and use it in GitHub Desktop.
Save netpoetica/70eae880cc0e152d499dcfad5e82ea8a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'game',
initial: 'initialize',
context: {
currentActor: undefined,
enemy: undefined,
player: undefined
},
states: {
initialize: {
entry: ['beginCombat'],
on: {
INITIALIZED: 'showMainMenu'
}
},
showMainMenu: {
on: {
PLAY_BTN_CLICK: 'determineNextActor'
}
},
determineNextActor: {
entry: ['getNextActor'],
on: {
CHOOSE_PLAYER: 'playerTurn',
CHOOSE_ENEMY: 'enemyTurn'
}
},
playerTurn: {
on: {
COMPLETE: 'checkWinCondition'
}
},
enemyTurn: {
entry: ['runEnemyTurn'],
on: {
COMPLETE: 'checkWinCondition'
}
},
checkWinCondition: {
entry: ['checkForWinner'],
on: {
PLAYER_WIN: 'gameOver',
ENEMY_WIN: 'gameOver',
NONE: 'determineNextActor',
}
},
gameOver: {
on: {
PLAY_BTN_CLICK: 'replay'
}
},
replay: {
entry: ['clearData', 'beginCombat'],
on: {
INITIALIZED: 'determineNextActor'
}
}
}
}, {
actions: {
beginCombat: async () => {},
clearData: async () => {},
getNextActor: () => {},
checkForWinner: () => {},
runEnemyTurn: () => {}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment