▩ TETRIS

Seven shapes, four blocks each — fill a row and it disappears

← Back to Fun Time
Next
Score
0
Lines
0
Level
1

⌨️ Controls

  • move left and right
  • rotate the piece
  • Z rotate the other way
  • soft drop (1 point a row)
  • Space hard drop (2 points a row)
  • P pause  •  R new game

🎯 How to play

  • Pieces fall from the top. Turn and slide them so they fit together.
  • Fill a whole row across and it vanishes — everything above drops down.
  • The grey outline shows where the piece will land.
  • Every 10 lines you go up a level and the pieces fall faster.
  • If a new piece cannot fit at the top, the game is over.

🏆 Scoring

  • 1 row = 100 × level
  • 2 rows = 300 × level
  • 3 rows = 500 × level
  • 4 rows at once = 800 × level — a real "Tetris"!
  • Clearing four rows in one go is worth more than four single rows. 🤔

🧑‍💻 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/tetris-shapes.js The seven shapes and how to turn them rotateMatrixClockwise, copyMatrix, createShuffledBag
lib/tetris-board.js The 10 × 20 grid and the line-clearing rules isRowFull, findFullRows, removeRows, canPlacePiece, dropDistance
lib/tetris-game.js The rules: falling, rotating, scoring, levels scoreForLines, levelForLines, dropIntervalForLevel, tryMove, lockPiece
lib/tetris-draw.js Painting the black-and-white picture drawBlock, drawGrid, renderNextPiece
lib/tetris-input.js Keyboard and touch buttons actionForKey, updateHeldKey

💡 Start easy: isRowFull(row) takes one row like [1,1,0,1] and answers true or false. Then try rotateMatrixClockwise — the trick that makes the whole game possible.

🛠️ Want to be walked through it? Build Tetris 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.