Overview
Classic Snake game implemented as a single self-contained HTML file. Grid-based gameplay with arrow key controls, collision detection, and food spawning. Built with strict error handling and an included test suite using Vitest. No external runtime dependencies.
Zone: staging/ — under evaluation, not yet promoted to apps/.
Related game projects: chess, cards-and-games
Tech Stack
| Component | Technology |
|---|---|
| Language | Vanilla JavaScript |
| Rendering | Canvas 2D API |
| Testing | Vitest 2.x |
| CI/CD | GitHub Actions (security.yml) |
| Entry Point | snake_v1.1.0.html (single file) |
No external runtime dependencies. Vitest is the only dev dependency.
Architecture
The entire game lives in snake_v1.1.0.html — a single self-contained file. No build step, no bundler.
Key implementation details:
- 400x400 canvas with 20px grid cells (20x20 grid)
- 150ms fixed movement interval
safeRun()wrapper for error recovery and safe fallback rendering- Type validation for segment and food coordinates
- Arrow key controls with 180-degree reversal prevention
Collision Detection
Three collision types handled:
- Boundary collision — snake head exits the 400x400 canvas grid
- Self-collision — head overlaps any existing body segment
- Food consumption — head occupies food cell (score increment, new food spawned)
Testing
Built-in test harness (separate from src/ + tests/ structure using Vitest). Tests cover:
- Collision scenarios
- Food boundary validation
- Mock data injection for reproducible runs
Run tests: npm test (executes vitest run)
Current Status
Zone: staging — Phase 2 compliance deployed on 2026-03-13
Compliance checklist:
-
security.yml— TruffleHog + Trivy + Semgrep (calibration mode through 2026-04-13) -
SECURITY.md— Vulnerability reporting -
.github/PULL_REQUEST_TEMPLATE.md -
.github/CODEOWNERS -
.security-config.yml
Pending gaps:
- Test coverage below 60% target
- General CI/CD lint+test pipeline not yet configured
- No pause/resume functionality
- No high score persistence — score and game state reset on page refresh
- No mobile/touch controls (keyboard only)
Known Limitations
Per README: no pause/resume, no difficulty scaling, no audio, no high score tracking, no mobile controls, no customizable colors. Fixed grid size and movement interval (150ms).
Lessons Learned
- Calibration mode for new staging repos: All new staging repos start security CI in calibration mode to establish a baseline before switching to enforcing mode. See 3-scanner-security-architecture.
- Single-file architecture is valid for small games: A self-contained HTML file eliminates build complexity for a proof-of-concept. Tradeoff is harder to test individual modules — the
src/+ Vitest structure addresses this separately.