/* ===================================================================== AROUND THE WORLD — Sport on Earth Games arcade Single-file canvas game in the Family Arcade house style. EMBED (inline):
CONTROLS: tap the court, click, or press Space to release each shot. RULES: shoot from 5 spots around the arc, in order (left corner, left wing, top, right wing, right corner). A sweeping needle sets your release — stop it in the green to make the shot. A make advances you one spot; a miss sends you back one spot, unless a chance token covers you (2 per game — the next shot after a miss is a free "chance" shot that can't send you back). 90 seconds on the clock. SCORING: make = 2 pts (final spot = 3) + 1 pt per second left when you clear the last spot. ===================================================================== */ (function () { "use strict"; /* ================= LEADERBOARD BACKEND — UPGRADE HOOK ================= Default: LOCAL board (localStorage top-10) so the game runs standalone. To switch to the shared family KV leaderboard later, set KV_ENABLED to true. The site must then serve the paper's functions/api/arcade.js with "around-the-world" added to its GAMES list and ARCADE_KV bound — the fetch calls below already mirror that API exactly: GET /api/arcade/leaderboard?game= -> { game, scores:[{manager,score,at}] } POST /api/arcade/score {game, manager, score} -> { ok, rank } No other code changes are needed. */ var KV_ENABLED = false; var GAME_ID = "around-the-world"; var LS_KEY = "fbiArcade." + GAME_ID; var LS_NAME = "fbiArcade.name"; /* Team Account identity (Batch 3.1, Task I, Oct 22, 2026): when a Team Account session is live, ACCT = { username, club } (from the accounts function's GET /api/accounts/me) and score saves go under that identity automatically — the visitor never re-types who they are. The board itself stays exactly what it has always been: this device's localStorage top-10 (KV_ENABLED above remains off — there is no /api/arcade backend on this site, and none is invented here). Guests keep the free-text name flow unchanged. */ var ACCT = null; function escapeHtml(s) { return String(s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); } function localScores() { try { return JSON.parse(localStorage.getItem(LS_KEY)) || []; } catch (e) { return []; } } function renderBoard(el, scores) { if (!scores || !scores.length) { el.innerHTML = "
  • No scores yet — be the first!
  • "; return; } el.innerHTML = scores.slice(0, 10).map(function (s, i) { return "
  • #" + (i + 1) + " " + escapeHtml(s.manager) + (s.club ? " · " + escapeHtml(s.club) : "") + " — " + s.score + "
  • "; }).join(""); } function loadBoard(el) { if (!KV_ENABLED) { renderBoard(el, localScores()); return; } fetch("/api/arcade/leaderboard?game=" + encodeURIComponent(GAME_ID)) .then(function (r) { return r.json(); }) .then(function (d) { renderBoard(el, d.scores || []); }) .catch(function () { el.innerHTML = "
  • Could not load scores.
  • "; }); } function saveScore(name, score, msgEl, boardEl) { if (ACCT) name = ACCT.username; name = (name || "").trim(); if (!name) { msgEl.textContent = "Enter your name first!"; return; } try { localStorage.setItem(LS_NAME, name); } catch (e) {} if (!KV_ENABLED) { var scores = localScores(); var entry = { manager: name.slice(0, 40), score: Math.floor(score), at: new Date().toISOString() }; if (ACCT) { entry.club = ACCT.club || ""; entry.account = true; } scores.push(entry); scores.sort(function (a, b) { return b.score - a.score; }); scores = scores.slice(0, 10); try { localStorage.setItem(LS_KEY, JSON.stringify(scores)); } catch (e) {} var rank = scores.indexOf(entry) + 1; msgEl.textContent = rank ? ("Saved! You rank #" + rank + " on this device's board.") : "Score saved!"; renderBoard(boardEl, scores); return; } fetch("/api/arcade/score", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ game: GAME_ID, manager: name, club: ACCT ? (ACCT.club || "") : "", score: Math.floor(score) }) }).then(function (r) { return r.json(); }) .then(function (d) { msgEl.textContent = d.rank ? ("Saved! You rank #" + d.rank + " on the family board.") : "Score saved!"; loadBoard(boardEl); }) .catch(function () { msgEl.textContent = "Could not save score."; }); } /* ================= SHARED ARCADE CSS (injected once per page) ================= */ if (!document.getElementById("hoopsArcadeCss")) { var st = document.createElement("style"); st.id = "hoopsArcadeCss"; st.textContent = ".hoops-arcade{max-width:440px;margin:0 auto;font-family:inherit;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}" + ".hoops-arcade *{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}" + ".hoops-arcade input,.hoops-arcade select{-webkit-user-select:text;user-select:text;-webkit-touch-callout:default}" + ".hoops-arcade .arcade-canvas{display:block;width:100%;max-width:400px;height:auto;margin:0 auto;background:#8a5a2b;border:3px solid var(--line,#d8cfc0);border-radius:8px;touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}" + ".hoops-arcade .arcade-ui{text-align:center;margin:12px 0}" + ".hoops-arcade .arcade-score{font-size:.85rem;margin-bottom:8px}" + ".hoops-arcade .arcade-score b{color:var(--red,#c8102e)}" + ".hoops-arcade .arcade-btn{background:var(--red,#c8102e);color:#fff;border:none;border-radius:6px;padding:10px 24px;font-size:1rem;font-weight:700;cursor:pointer}" + ".hoops-arcade .arcade-btn.small{padding:6px 12px;font-size:.8rem}" + ".hoops-arcade .arcade-btn:disabled{opacity:.5;cursor:default}" + ".hoops-arcade .arcade-msg{min-height:2.4em;font-size:.8rem;color:var(--muted,#666);margin:8px 0}" + ".hoops-arcade .arcade-name{display:flex;gap:8px;justify-content:center;margin:8px 0}" + ".hoops-arcade .arcade-name input{padding:8px;border:1px solid var(--line,#d8cfc0);border-radius:6px;font-size:.9rem;max-width:220px}" + ".hoops-arcade .arcade-board{margin-top:16px}" + ".hoops-arcade .arcade-board h3{font-size:1rem;margin-bottom:8px}" + ".hoops-arcade .arcade-board ol{list-style-position:inside;padding:0}" + ".hoops-arcade .arcade-board li{padding:4px 0;border-bottom:1px solid var(--line,#d8cfc0);font-size:.85rem}"; document.head.appendChild(st); } /* Long-press fix (iOS copy callout on held controls): kill the context menu anywhere inside an arcade mount. Installed once per page. */ if (!window.__hoopsNoCallout) { window.__hoopsNoCallout = true; document.addEventListener("contextmenu", function (e) { var t = e.target; if (t && t.closest && t.closest(".hoops-arcade")) e.preventDefault(); }); } /* ================= MOUNT ================= */ var mount = document.querySelector('[data-hoops-game="' + GAME_ID + '"]'); if (!mount) { mount = document.createElement("div"); mount.setAttribute("data-hoops-game", GAME_ID); var cs = document.currentScript; if (cs && cs.parentNode) cs.parentNode.insertBefore(mount, cs); else document.body.appendChild(mount); } mount.classList.add("hoops-arcade"); mount.innerHTML = '' + '
    ' + '
    Score: 0 • Spot: –/5 • Clock: 90s • Chances: 2
    ' + '
    ' + '
    Five spots around the arc — make to advance, miss and you slide back. Beat the 90-second clock!
    ' + '
    ' + '
    ' + "
    " + '

    Leaderboard — Around the World

    1. Loading…
    '; var cv = mount.querySelector("canvas"), ctx = cv.getContext("2d"); var el = { score: mount.querySelector(".sc"), spot: mount.querySelector(".spot"), clock: mount.querySelector(".clock"), chances: mount.querySelector(".chances"), msg: mount.querySelector(".arcade-msg"), start: mount.querySelector(".start"), name: mount.querySelector(".arcade-name input"), save: mount.querySelector(".save"), board: mount.querySelector(".arcade-board ol") }; try { el.name.value = localStorage.getItem(LS_NAME) || ""; } catch (e) {} /* Team Account session check (Task I): non-blocking; any failure simply leaves the guest flow exactly as it was. */ try { fetch("/api/accounts/me", { credentials: "same-origin" }) .then(function (r) { if (!r.ok) throw 0; return r.json(); }) .then(function (d) { if (!d || !d.ok || !d.username) return; ACCT = { username: d.username, club: d.club || "" }; el.name.value = d.username; el.name.readOnly = true; el.name.title = "Signed in — your scores save under your team account"; var hint = document.createElement("div"); hint.className = "arcade-msg acct-hint"; hint.textContent = "🏀 Signed in as " + d.username + (d.club ? " · " + d.club : "") + " — your high scores save under your account, no typing needed."; el.name.parentNode.parentNode.insertBefore(hint, el.name.parentNode); }) .catch(function () {}); } catch (e) {} /* ================= GAME ================= */ var W = 400, H = 480; var HOOP = { x: 200, y: 128 }; var SPOTS = [ { name: "Left Corner", x: 78, y: 322, gh: 10.5 }, { name: "Left Wing", x: 132, y: 350, gh: 9 }, { name: "Top of the Arc", x: 200, y: 362, gh: 8 }, { name: "Right Wing", x: 268, y: 350, gh: 9 }, { name: "Right Corner", x: 322, y: 322, gh: 7 } ]; var GAUGE_R = 62; var state = "idle"; // idle | playing | done var spot = 0, score = 0, makes = 0, attempts = 0, chances = 2, chanceArmed = false; var timeLeft = 90, elapsed = 0, finished = false; var needle = -80, needleDir = 1; var ball = null, floaters = [], netJiggle = 0, pauseT = 0; function spotNow() { return SPOTS[Math.min(spot, 4)]; } function sweepSpeed() { return Math.min(150, 100 + spot * 7 + attempts * 1.1); } // deg per second function reset() { state = "idle"; spot = 0; score = 0; makes = 0; attempts = 0; chances = 2; chanceArmed = false; timeLeft = 90; elapsed = 0; finished = false; needle = -80; needleDir = 1; ball = null; floaters = []; pauseT = 0; updateUI(); } function updateUI() { el.score.textContent = score; el.spot.textContent = (state === "idle" ? "–" : Math.min(5, spot + 1)) + "/5"; el.clock.textContent = Math.max(0, Math.ceil(timeLeft)); el.chances.textContent = chances; } function startGame() { reset(); state = "playing"; el.start.textContent = "Restart"; el.msg.textContent = "Spot 1 — the " + SPOTS[0].name + ". Stop the needle in the green!"; updateUI(); } function release() { if (state !== "playing" || ball || pauseT > 0) return; var s = spotNow(), a = needle, gh = s.gh; var kind = Math.abs(a) <= 2.5 ? "perfect" : Math.abs(a) <= gh ? "make" : Math.abs(a) <= gh + 6 ? "rimout" : "miss"; var tx = HOOP.x, ty = HOOP.y + 6; if (kind === "rimout") tx += a < 0 ? -13 : 13; if (kind === "miss") { tx += a < 0 ? -52 : 52; ty += 18; } ball = { x0: s.x, y0: s.y - 40, x1: tx, y1: ty, cx: (s.x + tx) / 2, cy: Math.min(s.y - 40, ty) - 130, t: 0, kind: kind, bouncing: false, bx: 0, by: 0, bvx: 0, bvy: 0, bt: 0 }; attempts++; } function endGame(won) { state = "done"; finished = won; if (won) { var bonus = Math.ceil(timeLeft); score += bonus; el.msg.textContent = "You went around the world! Time bonus +" + bonus + " — final score " + score + ". Save it to the board!"; } else { el.msg.textContent = "⏰ Time! You reached spot " + (spot + 1) + " of 5 — final score " + score + ". Save it to the board!"; } updateUI(); } function resolveBall() { var kind = ball.kind; if (kind === "perfect" || kind === "make") { var pts = spot === 4 ? 3 : 2; score += pts; makes++; netJiggle = 14; floaters.push({ x: HOOP.x, y: HOOP.y + 38, text: "+" + pts + (kind === "perfect" ? " SWISH!" : " Bucket!"), life: 1 }); chanceArmed = false; if (spot >= 4) { updateUI(); endGame(true); return; } spot++; el.msg.textContent = (kind === "perfect" ? "🎯 Pure! " : "Count it! ") + "On to spot " + (spot + 1) + " — the " + spotNow().name + "."; } else { floaters.push({ x: HOOP.x, y: HOOP.y + 38, text: kind === "rimout" ? "Off the rim!" : "No good…", life: 1 }); if (chanceArmed) { chanceArmed = false; spot = Math.max(0, spot - 1); el.msg.textContent = "The chance came up empty — back to spot " + (spot + 1) + ", the " + spotNow().name + "."; } else if (chances > 0) { chances--; chanceArmed = true; el.msg.textContent = "Missed — but a chance token covers you. This next shot can't send you back!"; } else { spot = Math.max(0, spot - 1); el.msg.textContent = kind === "rimout" ? "Rattled out — back to spot " + (spot + 1) + ", the " + spotNow().name + "." : "Off target — back to spot " + (spot + 1) + ", the " + spotNow().name + "."; } } updateUI(); } function nextAttempt() { needle = -80; needleDir = 1; pauseT = 0.55; updateUI(); } function drawCourt() { ctx.fillStyle = "#5b3a17"; ctx.fillRect(0, 0, W, 66); ctx.fillStyle = "rgba(255,255,255,.13)"; for (var i = 0; i < 30; i++) ctx.fillRect((i * 41) % W, 10 + (i * 11) % 42, 5, 5); ctx.fillStyle = "#b57e3e"; ctx.fillRect(0, 66, W, H - 66); ctx.fillStyle = "rgba(0,0,0,.05)"; for (var y = 96; y < H; y += 44) ctx.fillRect(0, y, W, 2); // Paint + three-point arc ctx.fillStyle = "rgba(200,16,46,.20)"; ctx.fillRect(HOOP.x - 54, 66, 108, 218); ctx.strokeStyle = "rgba(255,255,255,.75)"; ctx.lineWidth = 2; ctx.strokeRect(HOOP.x - 54, 66, 108, 218); ctx.beginPath(); ctx.arc(HOOP.x, 240, 168, 0.15 * Math.PI, 0.85 * Math.PI); ctx.stroke(); // Backboard + rim + net ctx.fillStyle = "#f4f4f4"; ctx.fillRect(HOOP.x - 36, HOOP.y - 34, 72, 28); ctx.strokeStyle = "#c8102e"; ctx.lineWidth = 2; ctx.strokeRect(HOOP.x - 36, HOOP.y - 34, 72, 28); ctx.strokeRect(HOOP.x - 11, HOOP.y - 23, 22, 15); ctx.strokeStyle = "#e25822"; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(HOOP.x - 16, HOOP.y); ctx.lineTo(HOOP.x + 16, HOOP.y); ctx.stroke(); ctx.strokeStyle = "rgba(255,255,255,.9)"; ctx.lineWidth = 1.5; var jig = netJiggle > 0 ? Math.sin(netJiggle * 1.4) * 3 : 0; for (var i = -1; i <= 1; i++) { ctx.beginPath(); ctx.moveTo(HOOP.x + i * 14, HOOP.y + 2); ctx.lineTo(HOOP.x + i * 7 + jig, HOOP.y + 26); ctx.stroke(); } } function drawSpotsAndShooter() { // Spot markers SPOTS.forEach(function (s, i) { var cleared = i < spot || state === "done" && finished; var current = state === "playing" && i === spot; var pulse = current ? 2.5 * Math.sin(Date.now() / 240) : 0; ctx.beginPath(); ctx.arc(s.x, s.y, 13 + pulse, 0, 7); ctx.fillStyle = cleared ? "#2ecc40" : current ? "#ffd700" : "rgba(255,255,255,.4)"; ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.5)"; ctx.lineWidth = 2; ctx.stroke(); ctx.fillStyle = "#17130c"; ctx.font = "bold 12px sans-serif"; ctx.textAlign = "center"; ctx.fillText(String(i + 1), s.x, s.y + 4); }); if (state === "idle") return; var s = spotNow(), gx = s.x, gy = s.y + 34; // Gauge arc background ctx.lineWidth = 13; ctx.strokeStyle = "rgba(0,0,0,.4)"; ctx.beginPath(); ctx.arc(gx, gy, GAUGE_R, Math.PI, 2 * Math.PI); ctx.stroke(); // Green zone var c = -Math.PI / 2, halfRad = s.gh * Math.PI / 180; ctx.strokeStyle = "#2ecc40"; ctx.beginPath(); ctx.arc(gx, gy, GAUGE_R, c - halfRad, c + halfRad); ctx.stroke(); // Perfect sliver ctx.strokeStyle = "#ffd700"; var pRad = 2.5 * Math.PI / 180; ctx.beginPath(); ctx.arc(gx, gy, GAUGE_R, c - pRad, c + pRad); ctx.stroke(); // Needle var na = (-90 + needle) * Math.PI / 180; var inGreen = Math.abs(needle) <= s.gh; ctx.strokeStyle = state === "playing" && !ball ? (inGreen ? "#2ecc40" : "#ffd700") : "#fff"; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(gx, gy); ctx.lineTo(gx + Math.cos(na) * (GAUGE_R + 10), gy + Math.sin(na) * (GAUGE_R + 10)); ctx.stroke(); ctx.fillStyle = "#fff"; ctx.beginPath(); ctx.arc(gx, gy, 5, 0, 7); ctx.fill(); // Shooter ctx.fillStyle = "rgba(0,0,0,.2)"; ctx.beginPath(); ctx.ellipse(s.x, s.y + 22, 15, 4, 0, 0, 7); ctx.fill(); var Fig = window.HoopsFig || null; if (Fig) { var apA = Fig.appearance('atw-shooter'); Fig.draw(ctx, { x: s.x, y: s.y + 22, s: 0.72, pose: 'shoot', t: Date.now() / 1000, ball: !ball, jersey: '#14418f', num: '11', skin: apA.skin, hair: apA.hair, hairColor: apA.hairColor }); } else { ctx.fillStyle = "#14418f"; ctx.beginPath(); ctx.arc(s.x, s.y + 6, 11, 0, 7); ctx.fill(); ctx.fillStyle = "#f2c79b"; ctx.beginPath(); ctx.arc(s.x, s.y - 12, 6.5, 0, 7); ctx.fill(); if (!ball) { ctx.fillStyle = "#e25822"; ctx.beginPath(); ctx.arc(s.x, s.y - 40, 8, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.35)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(s.x, s.y - 40, 8, 0, 7); ctx.stroke(); } } // Chance token pips for (var i = 0; i < 2; i++) { ctx.fillStyle = i < chances ? "#c9a227" : "rgba(255,255,255,.3)"; ctx.beginPath(); ctx.arc(178 + i * 22, 462, 6, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.4)"; ctx.lineWidth = 1; ctx.stroke(); } ctx.fillStyle = "rgba(255,255,255,.8)"; ctx.font = "10px sans-serif"; ctx.textAlign = "right"; ctx.fillText("CHANCES", 168, 466); // Clock readout ctx.fillStyle = timeLeft <= 15 ? "#ff5a4e" : "#fff"; ctx.font = "bold 22px sans-serif"; ctx.textAlign = "left"; ctx.fillText(Math.max(0, Math.ceil(timeLeft)) + "s", 12, 34); ctx.font = "11px sans-serif"; ctx.textAlign = "right"; ctx.fillStyle = "rgba(255,255,255,.85)"; ctx.fillText(spotNow().name.toUpperCase(), W - 12, 34); } function draw() { ctx.clearRect(0, 0, W, H); drawCourt(); drawSpotsAndShooter(); if (ball) { var bx, by; if (!ball.bouncing) { var t = ball.t; bx = (1 - t) * (1 - t) * ball.x0 + 2 * (1 - t) * t * ball.cx + t * t * ball.x1; by = (1 - t) * (1 - t) * ball.y0 + 2 * (1 - t) * t * ball.cy + t * t * ball.y1; } else { bx = ball.bx; by = ball.by; } ctx.fillStyle = "#e25822"; ctx.beginPath(); ctx.arc(bx, by, 9, 0, 7); ctx.fill(); ctx.strokeStyle = "rgba(0,0,0,.4)"; ctx.lineWidth = 1; ctx.beginPath(); ctx.arc(bx, by, 9, 0, 7); ctx.stroke(); } floaters.forEach(function (f) { ctx.globalAlpha = Math.max(0, f.life); ctx.fillStyle = "#ffd700"; ctx.font = "bold 17px sans-serif"; ctx.textAlign = "center"; ctx.fillText(f.text, f.x, f.y); ctx.globalAlpha = 1; }); if (state === "idle") { ctx.fillStyle = "rgba(0,0,0,.55)"; ctx.fillRect(0, 196, W, 92); ctx.fillStyle = "#fff"; ctx.font = "bold 23px sans-serif"; ctx.textAlign = "center"; ctx.fillText("🌍 AROUND THE WORLD", W / 2, 232); ctx.font = "14px sans-serif"; ctx.fillText("Five spots. Ninety seconds. Go around.", W / 2, 256); } if (state === "done") { ctx.fillStyle = "rgba(0,0,0,.72)"; ctx.fillRect(0, 178, W, 128); ctx.fillStyle = "#fff"; ctx.font = "bold 24px sans-serif"; ctx.textAlign = "center"; ctx.fillText(finished ? "🏁 Around the World!" : "⏰ Time!", W / 2, 214); ctx.font = "16px sans-serif"; ctx.fillText("Final score: " + score, W / 2, 240); ctx.fillText(finished ? ("Cleared with " + Math.ceil(timeLeft) + "s to spare • " + makes + "/" + attempts + " shooting") : ("Reached spot " + (spot + 1) + " of 5 • " + makes + "/" + attempts + " shooting"), W / 2, 264); ctx.font = "13px sans-serif"; ctx.fillText("Enter your name below and Save Score!", W / 2, 288); } } var lastFrame = Date.now(); function loop() { var now = Date.now(); var dt = Math.min(0.05, (now - lastFrame) / 1000); lastFrame = now; if (state === "playing") { if (pauseT > 0) pauseT -= dt; timeLeft -= dt; elapsed += dt; if (timeLeft <= 0) { timeLeft = 0; if (state === "playing") { ball = null; endGame(false); } } if (!ball && pauseT <= 0 && state === "playing") { needle += needleDir * sweepSpeed() * dt; if (needle >= 80) { needle = 80; needleDir = -1; } if (needle <= -80) { needle = -80; needleDir = 1; } } if (ball) { if (!ball.bouncing) { ball.t += dt / 0.55; if (ball.t >= 1) { var wasMake = ball.kind === "perfect" || ball.kind === "make"; resolveBall(); if (state !== "playing") { ball = null; } else if (wasMake) { ball = null; nextAttempt(); } else { ball.bouncing = true; ball.bx = ball.x1; ball.by = ball.y1; ball.bvx = (ball.x1 < HOOP.x ? -1 : 1) * (40 + Math.random() * 50); ball.bvy = -110; ball.bt = 0; } } } else { ball.bvy += 700 * dt; ball.bx += ball.bvx * dt; ball.by += ball.bvy * dt; ball.bt += dt; if (ball.bt > 0.45 || ball.by > H - 8) { ball = null; if (state === "playing") nextAttempt(); } } } if (netJiggle > 0) netJiggle--; floaters.forEach(function (f) { f.life -= dt * 0.9; f.y -= 26 * dt; }); floaters = floaters.filter(function (f) { return f.life > 0; }); if ((loop.frame = (loop.frame || 0) + 1) % 15 === 0) updateUI(); } draw(); requestAnimationFrame(loop); } /* ================= INPUT ================= Space only shoots while a run is live — with five games on one page, an idle-Space auto-start in every game would fire them all at once. */ /* Touch overhaul: flick/swipe on the court to shoot — a press that travels 26px+ releases the shot mid-gesture, the way a finger actually shoots. A plain tap still works: it releases on lift. */ var flickStart = null, flickFired = false; cv.addEventListener("pointerdown", function (e) { e.preventDefault(); if (state !== "playing") return; flickStart = { x: e.clientX, y: e.clientY }; flickFired = false; }); cv.addEventListener("pointermove", function (e) { if (!flickStart || flickFired || state !== "playing") return; var dx = e.clientX - flickStart.x, dy = e.clientY - flickStart.y; if (dx * dx + dy * dy >= 26 * 26) { flickFired = true; release(); } }); function flickEnd() { if (flickStart && !flickFired && state === "playing") release(); flickStart = null; } cv.addEventListener("pointerup", flickEnd); cv.addEventListener("pointercancel", function () { flickStart = null; }); window.addEventListener("keydown", function (e) { if (e.code === "Space") { if (document.activeElement && /INPUT|BUTTON/.test(document.activeElement.tagName)) return; e.preventDefault(); if (e.repeat) return; if (state === "playing") release(); } }); el.start.addEventListener("click", startGame); el.save.addEventListener("click", function () { saveScore(el.name.value, score, el.msg, el.board); }); loadBoard(el.board); reset(); draw(); loop(); })();