2048
A 2048 game built with the Onix module system and HTML/CSS UI, with no external
assets. The example uses the engine repository's Go module and a 540 × 850
logical viewport that scales while preserving its aspect ratio.
From the engine repository root, enter the example directory and run:
cd examples/2048
go run .
- Use the arrow keys, WASD, on-screen direction buttons, or swipe across the board
to move tiles.
- Matching tiles merge, adding the merged value to the score. Each tile can merge
only once per move.
- Each valid move spawns a 2 (90% chance) or a 4 (10% chance). Moves that leave the
board unchanged do not spawn tiles.
- Press Z or click the undo button to restore the previous board, score, and
random state. One level of undo is available.
- Press R or click the new-game button to restart. The session's best score
survives restarts and resets when the application exits.
- After reaching 2048, click the continue button or press Enter to keep playing.
When no moves remain, undo the last move or start a new game.
Project data and HTML live under resources/. Game state, merge rules, and input
handling live under resources/game/. Fixed-size arrays hold the board, line
buffers, and undo snapshot. Movement logic performs no heap allocations, and
the UI reuses DOM handles to update text and attributes.
Release builds enable staticHTML in resources/packages.json. The packager
checks all shipped HTML and CSS, including rules for classes the game toggles,
and omits unused text editing, select controls, Grid, table layout, CSS motion,
gradients, box shadows, filters and intrinsic image-size probing. Leave
this option off for projects that introduce new HTML or CSS features from Go
code or downloaded content at runtime.
The example enables precompileHTML and omitHTMLSource. Release builds ship
the parsed DOM and stylesheet in base.dat, including typed constants for
fixed CSS values. Font- and viewport-relative lengths resolve during layout.
Each mounted instance owns
its DOM and can change text, classes and attributes normally. Projects that
parse new markup or stylesheets at runtime should keep this option off.
From the engine repository root, validate the project, regenerate registration
code, and run the targeted tests:
go run ./editor/cmd/onix check ./examples/2048
go run ./editor/cmd/onix generate ./examples/2048
go test ./examples/2048 ./examples/2048/resources/game
Visual acceptance is manual, following the repository guidelines.