Skip to content

Instantly share code, notes, and snippets.

@tivac
Last active May 28, 2021 22:04
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 tivac/26014ee913503a5faa415a517d1a65cf to your computer and use it in GitHub Desktop.
Save tivac/26014ee913503a5faa415a517d1a65cf 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 hostMachine = Machine({
id: 'game-host',
initial: 'round_one',
context: {
active: false,
answering: false,
},
states: {
round_one: {
initial: "categories",
on: {
ROUND_OVER: 'round_two',
},
states: {
categories: {
on: {
DONE: "choosing",
},
},
choosing: {
on: {
QUESTION: "question",
},
},
question: {
initial: "reading",
states: {
reading: {
on: {
DONE_READING: "waiting",
},
},
waiting: {
on: {
BUZZER: {
target: "answering",
actions: "set_answering_player",
},
},
},
answering: {
entry: "start_timer",
exit: "clear_answering_player",
on: {
TIMER_EXPIRE: {
actions: send("INCORRECT"),
},
CORRECT: {
target: "done",
actions: [
"give_money",
"set_answering_player_as_active_player",
]
},
INCORRECT: {
target: "waiting",
actions: [
"take_money"
],
},
},
},
done: {
type: "final",
},
},
onDone: "choosing",
},
},
},
round_two: {
initial: "categories",
entry: "set_lowest_player_active",
on: {
ROUND_OVER: 'final_round',
},
states: {
categories: {
on: {
DONE: "choosing",
},
},
choosing: {
on: {
QUESTION: "question",
},
},
question: {
initial: "reading",
states: {
reading: {
on: {
DONE_READING: "waiting",
},
},
waiting: {
on: {
BUZZER: {
target: "answering",
actions: "set_answering_player",
},
},
},
answering: {
entry: "start_timer",
exit: "clear_answering_player",
on: {
TIMER_EXPIRE: {
actions: send("INCORRECT"),
},
CORRECT: {
target: "done",
actions: [
"give_money",
"set_active_player",
]
},
INCORRECT: {
target: "waiting",
actions: [
"take_money"
],
},
},
},
done: {
type: "final",
},
},
onDone: "choosing",
},
},
},
final_round: {
initial: "clue",
states: {
clue: {
on: {
DONE_READING: "answering",
},
},
answering: {
entry: "start_timer",
on: {
TIMER_EXPIRE: "reveal_answers",
},
},
reveal_answers: {
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment