This is a sliding tile puzzle game implemented in Elixir.
#Elixir #Phoenix #LiveView #SVG
To start the game server for the first time, fetch mix dependencies and start the Phoenix server:
$ mix setup
$ mix phx.server
Then navigate to http://localhost:4000.
Choose the grid size and click on the Play! button to start the game.
The game continues until a tile with number 2048 is created, which means you have won. The game is lost when no more free cells remain on the grid and there are no valid moves left.
Not yet implemented.
Launch the Elixir interactive shell with iex -S mix
and start a local game session with SN.start_local(<grid size>)
:
iex(1)> SN.start_local(4)
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 1, 0, 0]
[0, 0, 0, 0]
Enter a direction for the next move and press ENTER (r/l/u/d): r
[0, 0, 0, 0]
[0, 0, 0, 0]
[1, 0, 0, 1]
[0, 0, 0, 0]
Enter a direction for the next move and press ENTER (r/l/u/d): l
[0, 0, 1, 0]
[0, 0, 0, 0]
[2, 0, 0, 0]
[0, 0, 0, 0]
Enter a direction for the next move and press ENTER (r/l/u/d): u
[2, 0, 1, 0]
[0, 0, 0, 0]
[0, 0, 1, 0]
[0, 0, 0, 0]
Enter a direction for the next move and press ENTER (r/l/u/d): d
[0, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[2, 0, 2, 0]
Enter a direction for the next move and press ENTER (r/l/u/d): l
[1, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[4, 0, 0, 0]
...