Swap two shapes to make a line — then watch the chain reaction
← Back to Fun TimeThis game is split into small library files inside funtime/lib/, and every function has a comment saying exactly what goes in, what comes out, and the algorithm in plain English. Empty any function out, read its comment, and write it yourself.
| File | What it does | Good functions to try re-writing |
|---|---|---|
| lib/match3-rules.js | The rules: swapping, matching, falling, cascading | swapGems, findMatches, applyGravity, trySwap |
| lib/match3-draw.js | Painting six shapes that need no colour | drawShape, drawGrid, renderGame |
| lib/match3-main.js | The glue: clicks, the keyboard, the cursor | doAction, connectBoard, setUpGame |
💡 The big idea: make a copy, then decide. Every swap happens on a copy of the board first. If it turns out to be a bad move, the copy is thrown away and the real board never knew. Undoing is free when you never changed anything in the first place.
🛠️ Want to be walked through it? Build Match Three Yourself takes you through the key functions one step at a time and tests each one you write. There is a Python version too.