Score0
Best0
Length1
Runs0

ENGINE SPECIFICATION // ARCHITECTURAL GUIDE

How to play Snake

Controls for Snake
KeysAction
↑ ↓ ← →Steer
W A S DSteer
Drag / SwipeSteer
PPause
RRestart
MMute

On phones and tablets, use the on-screen tactile D-pad under the viewport.

About Snake

Snake is the classic grid game. Your snake starts as a single segment in the middle of a 22 by 22 playing field surrounded by a wall, and it moves on its own one cell at a time. You only choose the direction. Eat food to grow longer. Running into the wall or into any part of your own body ends the run.

You can't turn straight back on yourself: a 180-degree turn is ignored, so pressing the opposite direction by mistake won't kill you.

Scoring, levels and tips

  • Regular food, the solid square, scores 10 points and adds 3 segments.
  • Bonus food, the dashed circle, scores 50 points and adds 5 segments. There is always one on the board, and if you don't reach it within 15 moves it jumps to a new random cell.
  • The snake starts at one step every 0.18 seconds. Each piece of regular food shortens the step, down to 0.055 seconds after 120 pieces.
  • There are no lives or levels: one collision ends the run.
  • Your best score and total number of runs are saved in your browser.
  • Tip: speed depends on how much regular food you eat, not on time, so a safe, slow route costs you nothing.
  • Tip: bonus food is worth five times as much but adds more length. Skip it when reaching it would box you in.
  • Tip: once the snake is long, move in long lanes and keep the centre of the board open so you always have a way out.

How it's built

The game is written from scratch in TypeScript on an HTML canvas, with no game framework. The simulation is a separate module with no canvas or DOM code and uses a seeded random number generator, so an exact run can be replayed in tests. A shared engine updates at a fixed 60 steps per second, and the snake moves whenever its own step timer fills. New food is placed by listing every free cell and picking one at random, so it never appears inside the snake. Collisions are exact grid-cell comparisons.

Sound effects are synthesized with the Web Audio API, and the eat tone climbs in pitch as you collect more food. On phones you can swipe, drag across the board, or use the on-screen d-pad, and the game pauses itself when you switch tabs.