🐍 SNAKE

Eat the apples, grow longer, and never bite yourself

← Back to Fun Time
Score
0
Length
3
Level
1
Best
0

⌨️ Controls

  • steer the snake
  • W A S D work too
  • P or Space pause
  • R new game
  • Any arrow key starts a paused game.

🎯 How to play

  • The snake never stops moving — you only choose which way it turns.
  • Eat an apple and the snake grows one square longer.
  • Hit a wall or your own body and the game ends.
  • You cannot turn straight back on yourself — no U-turns!
  • Fill the entire board to win. (Nobody has ever done it. Probably.)

🏆 Scoring

  • Each apple is worth 10 × your level.
  • Every 5 apples you go up a level.
  • Each level makes the snake 15 ms faster, down to a very scary 70 ms per step.
  • So the long game is worth far more than the short one. 🤔

🧑‍💻 For young coders: build this game yourself

This game is not one big lump of code. It is split into five small library files inside the funtime/lib/ folder, and every single function has a comment above it saying exactly what goes in, what comes out, and the algorithm in plain English.

That means you can delete the body of any function, read its comment, and write it yourself — the rest of the game keeps working as soon as yours is correct.

File What it does Good functions to try re-writing
lib/snake-grid.js Squares, positions and directions samePosition, addDirection, containsPosition, randomEmptyCell
lib/snake-game.js The rules: crawling, eating, growing, dying moveSnake, stepGame, turnSnake, scoreForFood, stepIntervalForLevel
lib/snake-draw.js Painting the black-and-white picture drawSegment, drawHead, drawFood
lib/snake-input.js Keyboard and touch buttons actionForKey, directionForAction
lib/snake-main.js The glue between the page and the rules updateScoreboard, buildActions, gameLoop

💡 The big idea: the snake is just a list of squares. Moving it means adding a head and dropping a tail; eating means adding a head and keeping the tail. That is the whole game, in moveSnake.

🛠️ Want to be walked through it? Build Snake Yourself takes you through twelve of these functions one step at a time, tests each one you write, and shows the game growing as you go.