How the games are built
A short tour of the code: one canvas, one loop, a few hundred lines.
All eight games live in a single HTML file of about fifteen kilobytes. There are no images, libraries or downloads. This is how it fits.
One canvas
Every game draws on the same 320 by 320 pixel canvas using filled rectangles and a little text. The browser scales the canvas to your screen and keeps the pixels sharp.
A loop per game
Action games run a timer that fires a fixed number of times per second. Each tick does three things in order: read the keys, update the state, redraw the screen. Snake ticks about eight times a second, the ball games fifty.
Puzzle games have no timer at all. They redraw only when you press a key or tap, which is why they use almost no battery.
State is just numbers
- Snake is a list of grid positions; moving means adding a head and removing the tail.
- Blocks is a grid of twenty rows by ten columns plus the current piece. Rotation turns the piece's small matrix a quarter turn.
- Mines stores two arrays: where the mines are and which cells are open. The numbers are counted on demand.
- Fifteen shuffles by making three hundred random legal moves from the solved position, so every puzzle can be solved.
Input
Keyboard and touch feed the same function. The on-screen buttons simply pretend to be keys, so no game needs special code for phones.
No storage
Scores are kept in memory only. Nothing is written to your device and nothing is sent anywhere.