Ten mines, eighty-one squares, and nothing but logic
← 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/mines-rules.js | The rules: the neighbours, the mines, the flood fill | neighbours, countMines, placeMines, revealCell |
| lib/mines-draw.js | Painting the squares, the flags and the mines | drawCovered, drawFlag, renderGame |
| lib/mines-main.js | The glue: left click, right click, long press | doAction, connectBoard, gameLoop |
💡 The big idea: flood fill. Keep a to-do list of squares; take one off, deal with it, and if it is blank put its neighbours on the list. When the list is empty you are finished. That is how one click opens a whole field — and how the paint bucket works in every drawing program.
🛠️ Want to be walked through it? Build Minesweeper Yourself takes you through the key functions one step at a time and tests each one you write. There is a Python version too.