An OTP application that provides a websocket API for the time-consuming game, 2048.
-
tofe_app: The main application behavior module, implementing callbacks from the application behavior. -
tofe_sup: The main supervisor, responsible for managingtofe_game_sup, which oversees game processes. -
tofe_game: A game-managing process based on the Generic Server. It handles game logic, manages players, and maintains the game and chat history. -
tofe_ws: A websocket handler implementing callbacks from Cowboy's WebSocket Handler, managing the WebSocket connection. -
tofe_protocol: A functional API encapsulatinggen_servercommunication for game purposes. -
tofe_grid&tofe_vector: API modules managing grid transitions during the game. -
tofe_utils: A collection of utility functions for various purposes.
- Erlang/OTP: Version 23.0 or higher
$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf
$ . $HOME/.asdf/asdf.sh
$ asdf plugin add erlang
$ asdf install erlang 23.0
$ asdf global erlang 23.0$ ./rebar3 compile$ ./rebar3 shell$ ./rebar3 as test do cover --reset, eunit --cover, ct --cover, cover --verbose$ ./rebar3 as test shellThe ./sys.config file includes all the necessary configuration parameters required to start the webserver app.
The test cases are written using EUnit for unit testing and Common Test for more complex cases.
All unit test modules have a _test suffix before the file extension:
$ ./test/*_test.erlUnit test coverage is particularly thorough for grid-based modules that do not require complex management logic between players.
More complex tests, such as those covering tofe_game and tofe_ws with multiple players and chats, are written using the Common Test framework:
$ ./test/*_SUITE.erlSee the all/0 definitions for the test cases.
| Module | Coverage |
|---|---|
tofe_protocol |
100% |
tofe_vector |
100% |
tofe_grid |
100% |
tofe_sup |
100% |
tofe_game_sup |
73% |
tofe_app |
100% |
tofe_ws |
81% |
tofe_game |
85% |
tofe_utils |
100% |
| Total | 90% |
$ ./rebar3 release$ ./_build/default/rel/tofe/bin/tofe {boot command}startstart_boot <file>foregroundstoprestartrebootpidpingconsoleconsole_cleanconsole_boot <file>attachremote_consoleupgradedowngradeinstalluninstallversionsescriptrpcrpctermsevalstatusundefined
- Document the WebSocket API using AsyncAPI.
- Implement the UI (UI implementation ideas).