Created
November 29, 2020 18:10
-
-
Save netpoetica/70eae880cc0e152d499dcfad5e82ea8a 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
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