Skip to content

2048 game: merge equal tiles until you add up to 2048

License

Notifications You must be signed in to change notification settings

mgrojo/play_2048

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cf45562 · Nov 19, 2023

History

73 Commits
Nov 16, 2023
Sep 26, 2021
Sep 17, 2022
Dec 4, 2022
Sep 4, 2021
Aug 8, 2021
Mar 20, 2023
Nov 19, 2023
Sep 17, 2022
Aug 9, 2021
Mar 20, 2023

Repository files navigation

Build Alire Alire CI/CD Download Gitter chat Mentioned in Awesome Ada Screenshot of Play 2048!

This is yet another implementation of the 2048 game, implemented in Ada using ASFML for graphics and ada-toml for saving state.

It has been tested under Windows 10 and Ubuntu Linux 20.04.

Features

  • Different themes can be switched while playing. Five themes are included, but the user can add up to nine themes, following the same structure.
  • Best score and best time
  • Fullscreen
  • Saving of the state
  • Undo last move
  • Three board sizes:
    • Small (3x3): difficult, beat your score!
    • Default (4x4): normal, you can do it!
    • Easy (5x5): easy, beat your best time!

How to build

  • Install Alire
  • Build using alr build. All the dependencies are installed and managed by Alire.
  • Run using alr run (mandatory in Windows so it finds installed libraries) or directly from the working directory: ./play_2048 (Linux only).

How to install

The game can be installed using Alire 2.0 with this command:

alr install

Refer to Alire documentation on how to add the Alire default installation to the PATH variable or how to change the default installation prefix.

If Alire 2.0 is not available, you can still install the application using something like this:

sudo make PREFIX=/opt/play_2048 install

If you're interested in building the AppImage file:

make AppImage

How to play

Use arrow keys to move tiles. When two adjacent tiles with the same number are merged, their numbers add up. Keep merging tiles until you get to 2048. If the board is full and there is no possible move (no adjacent tiles with the same number), you lose.

To change the board size, export the enviroment variable PLAY_2048_SIZE to the number of cells per size, for example, in Linux/Bash:

export PLAY_2048_SIZE=3

After a change in the board size, the board state will not be restored.

Keys:

  • R - restart game
  • Q - quit game
  • Arrow keys - move tiles
  • U - undo last move
  • F11 - toggle fullscreen mode
  • Tab - switch theme

Attribution

The initial implementation of the game logic was taken from Rosetta Code, although it has been mostly rewritten.

Fonts used in the themes: Noto Serif (SIL Open Font License) for Theme 5 and DeJa Vu Sans (MIT License) for the rest.