Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ac-unefm/snake-game/llms.txt

Use this file to discover all available pages before exploring further.

Snake Classic Game organises play into sessions. Every session consists of exactly 5 consecutive attempts. A row of 5 dots above the canvas tracks your progress through the session: a yellow dot marks the currently active attempt, and purple dots mark completed ones. Once all 5 attempts are finished, a detailed results panel appears automatically.

Scoring

You earn one point for each food item eaten. The current score is displayed in real time in the HUD as SCORE: N. Whenever your score exceeds the stored best, the best is updated immediately — both in the HUD (BEST: N) and in localStorage under the key snakeBest — so your record is never lost even if the page is closed mid-session.

Attempt flow

1

Start attempt 1

From the idle screen, press Enter, Space, any arrow key, or tap the canvas to begin the first attempt. The snake starts near the centre of the grid moving right.
2

Play

Guide the snake to eat the red food. Each food item eaten grows the snake by one segment and increments the score by 1. The attempt ends immediately if the snake hits a wall or collides with any part of its own body.
3

Between attempts

After the attempt ends a status message appears showing your score and prompting you to press Enter (or tap) for the next attempt. The completed dot turns purple and the next dot turns yellow.
4

Session complete

After attempt 5 ends, the message “CARGANDO RESULTADOS…” is shown briefly, then — after a 1.4-second delay — the session results panel slides into view automatically with full per-attempt and aggregated statistics.

Per-attempt metrics

Every attempt records the following fields, which are collected into an AttemptRecord object and stored in the sessionAttempts array:
FieldDescription
scoreFood items eaten during the attempt
maxLevelHighest level reached before the attempt ended
durationTotal length of the attempt in milliseconds
stepsTotal cells traversed (one move = one cell)
maxSpeedCpsPeak speed in cells/second, calculated as 1000 / minTick
maxSpeedCps reflects the fastest tick interval ever reached during the attempt. For example, if the snake reached level 8 (tick = 45 ms), the recorded peak speed is 1000 / 45 ≈ 22.2 cells/second.

Session statistics panel

After the fifth attempt, the results panel displays two sections: Per-attempt table — one row per attempt showing attempt number, score, max level, duration, steps traversed, and peak speed. The attempt with the highest score is highlighted in purple and marked with a symbol. If multiple attempts share the same top score, the first one is highlighted. Aggregated stats grid — a two-column grid of session-wide figures:
StatDescription
Best scoreHighest single-attempt score in the session
Average scoreMean score across all 5 attempts
Total foodSum of all food items eaten
Total timeCombined duration of all 5 attempts
Average durationMean attempt length
Total distanceTotal cells traversed across all attempts
Max level (session)Highest level reached in any attempt
Max speed (session)Peak cells/second recorded in any attempt
EfficiencyFood earned per 100 cells traversed (see below)
At the bottom of the panel a “Nueva sesión” button resets all session state (sessionAttempts, currentAttempt, all progress dots) and immediately starts a fresh 5-attempt session.

Efficiency formula

Efficiency = (total food / total steps) × 100. A higher value means you took more direct routes to food. A perfectly efficient run (straight-line path every time) would approach 100%; typical play produces values in the single digits.

Best score persistence

At page load, the stored best is retrieved with readBestScore(), which reads localStorage.getItem('snakeBest'). Whenever a new best is set during play, saveBestScore() writes it back with localStorage.setItem('snakeBest', value). Both functions wrap their storage calls in try/catch blocks, so a browser privacy setting or a full storage quota will never throw an unhandled error and never crash the game — the best simply resets to 0 for that session.

Build docs developers (and LLMs) love