Awesome
Elm 2048
An Elm version of Gabriele Cirulli's 2048 game
Deployed to Github Pages: https://stepheneb.github.io/elm-2048/
MIT License
I wrote this to learn more about Elm.
Possibly helpful/useful/interesting features:
- Save game state to local storage.
- JSON Encoding of
Int
,Bool
,Union Type
, andList
ofTile
records. - Send game state to JavaScript where it is saved in local storage.
- Load game state on application startup.
- JavaScript extracts game state from local storage, converts to JSON and passes to application via
flags
. - Handle successful or failed JSON decoding of game state.
- Model
Tiles
usingHtml.Keyed
to allow CSS animations to work effectively. - Use
Events.onKeyDown
andSubscriptions
to handle arrow keys forTile
movement.- Additional JavaScript code to prevent arrow keyboard events bubbling and causing page scroll.
- Use JavaScript and incoming
Port
to turn touch interface swipes intoTile
movements. - Game state record is nested one-level deep in Model.
- Helper functions work with
Update Msg
branches to cleanly handle game state record manipulation and updates.
- Helper functions work with
This project is bootstrapped with Create Elm App. Readme generated by elm-app
: elm-app-readme.md).
Build dependencies:
To build locally:
% git clone https://github.com/stepheneb/elm-2048
% cd elm-2048
% nvm use
% yarn
% yarn build-css
% yarn start
Local development run:
% yarn start
If you are also changing the scss
styles open a second shell and run:
$ yarn watch-css
Deploy to Github Pages:
% yarn build-deploy