feat(js): m11 pong capstone (model, rules, view, app, page) and polling smoke test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas Winther
2026-10-28 23:59:25 +01:00
co-authored by Claude Sonnet 5.5
parent fd7c5f2acf
commit 1d1d918805
16 changed files with 3090 additions and 3 deletions
+38
View File
@@ -0,0 +1,38 @@
// m11 pong model: the same ideas as the snake model, for a different game.
/** @typedef {{ball: {x: number, y: number}, vel: {dx: number, dy: number}, player: number, cpu: number,
* held: {up: boolean, down: boolean}, score: {player: number, cpu: number},
* status: 'Playing'|'Over', seed: number, frame: number}} PongState */
// The court, in cells. `player` and `cpu` are the y of the top cell of each paddle.
export const W = 80
export const H = 50
/** Pixels per cell. */
export const PCELL = 8
/** Paddle height in cells. */
export const PADDLE = 8
/** Column of the player's paddle (left) and the cpu's paddle (right). */
export const PLAYER_X = 2
export const CPU_X = 77
/** Points needed to win the match. */
export const WIN = 5
export const initialPong = (seed) => ({
ball: { x: 40, y: 25 },
vel: { dx: 1, dy: 1 },
player: 21,
cpu: 21,
held: { up: false, down: false },
score: { player: 0, cpu: 0 },
status: 'Playing',
seed,
frame: 0,
})
/** Everything that can happen in a match, as data. */
export const PongAction = {
Press: (key) => ({ tag: 'Press', key }),
Release: (key) => ({ tag: 'Release', key }),
Frame: { tag: 'Frame' },
Restart: { tag: 'Restart' },
}