Skip to content

Instantly share code, notes, and snippets.

View Spiralis's full-sized avatar

Ronny Hanssen Spiralis

View GitHub Profile
@Spiralis
Spiralis / XState Handball Match Machine.js
Last active April 10, 2019 20:39
A simplified XState statecharts state-machine for running a handball game. Typically used with a control app for the match officials. Note: There are still parts missing in this sample, like disciplinary actions (2 min, yellow and red cards), as well as who made the goals, and adjusting the match-clock (adjusting the data on the fly). But, it is…
// Available variables:
// Machine (machine factory function)
// XState (all XState exports)
function pad(n, width) {
var n = n + "";
return n.length >= width ? n : new Array(width - n.length + 1).join("0") + n;
}
function displayTime(ticksInSecs) {