Seven shapes, four blocks each — fill a row and it disappears
← Back to Fun TimeThis 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.