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 WintherandClaude Sonnet 5.5 committed 2026-10-28 23:59:25 +01:00
1 parent fd7c5f2acf
commit 1d1d918805
16 files changed
+3090 -3

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
// m11 pong view: the same Scene shapes as the snake view, so the same drawScene and runtime draw it.
import { PCELL, PADDLE, PLAYER_X, CPU_X } from './model.js'
const rect = (x, y, w, h, color) => ({ tag: 'Rect', x, y, w, h, color })
const text = (x, y, str, size) => ({ tag: 'Text', x, y, text: str, color: '#ffffff', size, align: 'center' })
const paddle = (column, y) => rect(column * PCELL, y * PCELL, PCELL, PADDLE * PCELL, '#ffffff')
const overlay = (state) =>
state.status === 'Over'
? [
text(320, 200, state.score.player > state.score.cpu ? 'You Win!' : 'CPU Wins', 32),
text(320, 230, 'Press R to restart', 16),
]
: []
export const pongView = (state) => [
rect(0, 0, 640, 400, '#111111'),
paddle(PLAYER_X, state.player),
paddle(CPU_X, state.cpu),
rect(state.ball.x * PCELL, state.ball.y * PCELL, PCELL, PCELL, '#ffeb3b'),
text(320, 30, `${state.score.player} ${state.score.cpu}`, 24),
...overlay(state),
]