2048.cpp

? Fully featured terminal version of the game "2048" written in C++

Github stars Tracking Chart

2048.cpp

Build Status
Build status
Codacy Badge
Language grade: C/C++
Made with Love in India
Run on Repl.it

Terminal version of the game "2048" written in C++.

:tada: Featured on GitHub's Twitter and Facebook pages! :tada:

Setup

The game and code is made to run natively on the GNU/Linux and MacOS platforms, but cross-platform compatibility for Windows has been added too.

Requirements

  • C++11 compiler (e.g. g++, clang++, pgc++, icpc, etc.)
  • Virtually any platform including:
    • Linux
    • MacOS
    • Windows (via Cygwin or Windows Subsystem for Linux)
  • CMake or Meson

Installation

  1. Open your terminal in your preferred directory and clone this project:
git clone https://github.com/plibither8/2048.cpp
  1. Enter the project's build directory:
cd 2048.cpp/build

For both CMake and Meson, the default C++ compiler on your system will be used.
If you wish to manually select a C++ compiler, optionally add CXX=clang++ cmake or CXX=clang++ meson etc.

Building with CMake

  1. Generate build configuration
cmake ../
  1. Build the executable
cmake --build .
  1. Install the program (optional)
cmake --build . --target install
  1. Run the program and play the game! :tada:
2048    # run `./2048` if game is not installed

Building with Meson

  1. Generate build configuration
meson ../
  1. Build the executable
ninja
  1. Install the program (optional)
meson configure --prefix=$HOME/.local
ninja install
  1. Run the program and play the game! :tada:
2048    # run `./2048` if game is not installed

Contributing

First of all, thank you for contributing :smile:! A few things to note:

  • If you have found a bug, or have a feature that you'd like implemented, raise an issue.

  • If you have proposed a pull request, make sure that you run clang-format on the source code (both, .cpp and .hpp) files if you've made changes there.

  • In your local repository, run git update-index --skip-worktree ./data/*.txt to ensure that changes to the data files are not tracked by git, and thus are not staged.

Thanks

I deeply appreciate the help of the following people:

  • Michael Hirsch
    • cleaned up the code,
    • organised the header files in a better way for a more efficient build,
    • added the AppVeyor CI,
    • added the Meson build system and, fixed CMake and added install feature.
  • Aiman Ismail added support for Vim keybinding.
  • Patrik Huber fixed a typo in the Readme.
  • zestze changed cstdlib rand to C++ random int generator.
  • Pascal J. Bourguignon added support for ANSI arrow keys.
  • Jean-Michaël Celerier added CMakeLists.txt file.
  • comwrg made the duration in the statistics and highscores human-readable, wrapping seconds to minutes and hours.
  • Christian Bundy replaced the ugly -, + and, with box-drawing characters.
  • Tor E Hagemann fixed issue #10, causing unwanted character 1 to be printed.
  • farazxameer implemented feature to save a game state and continue from a saved game state, refined game logic.
  • drodil implemented checks to ascertain existence of data files, fixed issue #12
  • Aviskar KC added arrow keys to game instructions.
  • Peter Squicciarini fixed readme instructions.
  • Mark Fischer, Jr. fixed a typo.
  • Hugo Brandão completely reorganised the existing project structure and updated the build method to enfore CMake.
  • Alton Alvarez fixed a typo.
  • cawvyoct made the source code much, much easier to read: removed most magic numbers, replacing them with variables to ease maintenance. Implemented clang-format.
  • Cong edited the Game class constructor.
  • Tien Do added the 'exit' option in the main menu, updated the CMakeLists.txt file and made Color enum to a scoped enum.
  • ScorrMorr made many methods consts.
  • tangmengqiu fixed an error-causing instruction step in the readme.

Maintainers

Notes

[GameBoard].getTile(2,0) refers to the 0th tile (or column) in 2nd row as in this case, x = 0 and y = 2. The specific tile is denoted the by '@' symbol in the following gameboard:

Note: row and column indexing starts at 0.

┌──────┬──────┬──────┬──────┐
│      │      │      │      │
├──────┼──────┼──────┼──────┤
│      │      │      │      │
├──────┼──────┼──────┼──────┤
│   @  │      │      │      │
├──────┼──────┼──────┼──────┤
│      │      │      │      │
└──────┴──────┴──────┴──────┘

To-Do

  • Add start menu [19/04/2018]
  • Save highscore / score [21/04/2018]
  • Save a game state and play from a saved game state
  • AI (Abandoned indefinitely)

License

Copyright (c) Mihir Chaturvedi. All rights reserved.

Licensed under the MIT License.

Main metrics

Overview
Name With Ownerplibither8/2048.cpp
Primary LanguageC++
Program languageC++ (Language Count: 3)
Platform
License:MIT License
所有者活动
Created At2018-04-02 07:14:05
Pushed At2024-06-24 07:13:19
Last Commit At2024-06-24 12:43:19
Release Count0
用户参与
Stargazers Count2.2k
Watchers Count37
Fork Count323
Commits Count376
Has Issues Enabled
Issues Count38
Issue Open Count16
Pull Requests Count71
Pull Requests Open Count7
Pull Requests Close Count28
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private