2048 — written in Mere
A tiny 2048
compiled from Mere to
WebAssembly. The board is drawn as text into a <pre>
via dom_set_text, and the arrow keys drive it through
dom_on_key — a keyboard binding added to
contrib/dom for this game. Turn-based, so no game loop or
timer is needed; each keypress runs one move in Mere.
Use the arrow keys to slide tiles. Merge equal tiles to reach 2048. (Click the board first if the keys don't respond.)
loading…
What's happening
-
mere -w g2048.merelowers the game — a 16-slotvecboard, the slide/merge row logic, a tiny LCG for tile spawns — to WebAssembly. -
dom_on_keyregisters a globalkeydownlistener; the pressed key name ("ArrowLeft", …) is passed to a Mere closure that applies one move, spawns a tile if the board changed, and redraws the<pre>. -
No randomness FFI is used: tile spawns come from a pure-Mere
linear-congruential generator seeded from a mutable
vecslot, so the game is fully self-contained in the Wasm module.