๐ŸŽฎ Fully featured terminal version of the game

Overview

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++.

๐ŸŽ‰ Featured on GitHub's Twitter and Facebook pages! ๐ŸŽ‰

2048 in action!

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! ๐ŸŽ‰
2048    # run `./2048` if game is not installed

OR

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! ๐ŸŽ‰
2048    # run `./2048` if game is not installed

Contributing

First of all, thank you for contributing ๐Ÿ˜„ ! 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.

Comments
  • Fix CI, add Meson build system, fix CMake, add install feature

    Fix CI, add Meson build system, fix CMake, add install feature

    • corrected errors in Travis-CI and AppVeyor setup
    • corrected errors in CMake (never glob source files, must set C++14 std)
    • add Meson, a modern alternative to CMake
    opened by scivision 15
  • fix: various: added back endless play after winning game

    fix: various: added back endless play after winning game

    • When player wins the game, the game asks if the player wants to continue in "Endless Mode".
    • By typing in x or pressing x in Endless Mode, the game ends.
    opened by cawvyoct 8
  • Change file structure and update build method

    Change file structure and update build method

    Resolves #30

    • It now has a dependency on cmake
    • Adding new files and headers now does not require modification of build file
    • Updated README.md with new instructions
    • Removed old Makefile as it was unnecessary
    help wanted 
    opened by jhugobb 8
  • Better demo gif for README

    Better demo gif for README

    The current demo gif on the repository's README page is alright, but it looks ugly when compared to the beautiful terminal gifs I have seen on other repositories (eg. Sindre Sorhus's repos). Anyone who can create a better gif than the current one, showcasing most of the features of the game (make sure to do a git pull), I'd be obliged. Thanks!

    enhancement help wanted good first issue 
    opened by plibither8 7
  • Fix: Convert Menu class to a namespaced area

    Fix: Convert Menu class to a namespaced area

    This PR cleans up the API to call the "Main Menu" for 2048.cpp.

    One only just needs to add menu.hpp and to call Menu::startMenu().

    For example:

    #include "menu.hpp"
    int main() {
      Menu::startMenu();
    }
    

    Functions needed for the 2048.cpp's Main Menu are contained within (menu.cpp's) own anonymous namespace.

    opened by cawvyoct 5
  • Issue #22

    Issue #22

    Partial fix which ignores arrow, escape and non alphanumeric characters.

    I didn't fix the character limit issue as it seemed like a separate issue. If I change the file the name is more than 18 chars long, scoreboard breaks. I will try to find a better solution there.

    opened by mayurdw 5
  • Check for existence of data files before performing operations

    Check for existence of data files before performing operations

    โ–ถ ./build/2048.out
    
       /\\\\\\\\\          /\\\\\\\                /\\\         /\\\\\\\\\
      /\\\///////\\\      /\\\/////\\\            /\\\\\       /\\\///////\\\
      \///      \//\\\    /\\\    \//\\\         /\\\/\\\      \/\\\     \/\\\
                 /\\\/    \/\\\     \/\\\       /\\\/\/\\\      \///\\\\\\\\\/
               /\\\//      \/\\\     \/\\\     /\\\/  \/\\\       /\\\///////\\\
             /\\\//         \/\\\     \/\\\   /\\\\\\\\\\\\\\\\   /\\\      \//\\\
            /\\\/            \//\\\    /\\\   \///////////\\\//   \//\\\      /\\\
            /\\\\\\\\\\\\\\\   \///\\\\\\\/              \/\\\      \///\\\\\\\\\/
            \///////////////      \///////                \///         \/////////
    
    
    
      Welcome to 2048!
    
              1. Play a New Game
              2. View Highscores and Statistics
    
      Enter Choice: 2
    
      SCOREBOARD
      ----------
    
      No saved scores.
    
    
    
      STATISTICS
      ----------
    
      +--------------------+------------+
      | Best Score         | 140732916466960 |
      | Game Count         |          1 |
      | Number of Wins     | -1837137648 |
      | Total Moves Played | 140734694615213 |
      | Total Duration (s) | 3.25939e-311 |
      +--------------------+------------+
    
    bug good first issue hacktoberfest 
    opened by comwrg 5
  • Character `1` being printed

    Character `1` being printed

    I'm not sure why, but the character 1 keeps getting printed to the console for me. I'm using Zsh and GNOME Terminal. For example:

    1   /\\\\\\\\\          /\\\\\\\                /\\\         /\\\\\\\\\    1
    1  /\\\///////\\\      /\\\/////\\\            /\\\\\       /\\\///////\\\  1
    1  \///      \//\\\    /\\\    \//\\\         /\\\/\\\      \/\\\     \/\\\  1
    1             /\\\/    \/\\\     \/\\\       /\\\/\/\\\      \///\\\\\\\\\/   1
    1           /\\\//      \/\\\     \/\\\     /\\\/  \/\\\       /\\\///////\\\  1
    1         /\\\//         \/\\\     \/\\\   /\\\\\\\\\\\\\\\\   /\\\      \//\\\ 1
    1        /\\\/            \//\\\    /\\\   \///////////\\\//   \//\\\      /\\\  1
    1        /\\\\\\\\\\\\\\\   \///\\\\\\\/              \/\\\      \///\\\\\\\\\/   1
    1        \///////////////      \///////                \///         \/////////     1
    
    
    
    1  Welcome to 2048!1
    
              1. Play a New Game
              2. View Highscores and Statistics
    
      Enter Choice: 
    
    

    Any ideas why this might be happening?

    opened by christianbundy 5
  • Fix: Refactored Inputs and some UI from Game Logic

    Fix: Refactored Inputs and some UI from Game Logic

    • "Input" (Keypress) logic and "Game Action" logic have been separated quite a bit. This helps breaks up the main input function into smaller ones based on a "keypress" style.

      • Keypress styles now have their own functions.
        • This makes it easier to test if keypresses are working.
        • Keypresses now "flag an intent" for the game "to do X action".
    • "Flag"-based processing introduced in the game. In this PR...

      • GameStatusFlag for all game-related statuses like win / lose / save (and returning soon endless-mode)...
      • IntendedMoveFlag for all move-related statuses like "tumbleLeft" or "tumbleRight".
        • This will help in creating "replayable"-based tests.
        • Will be encapsulated / separated further in a future PR.
      • Depending on which flags enabled / disabled, game-logic does action (which is) flagged accordingly.
    • "Printing" of UI text is encouraged to be in its own specialised function.

    Will clean up code in further PRs.

    opened by cawvyoct 4
  • Save scores & statistics in all board size

    Save scores & statistics in all board size

    save scores of all sizes of game board. Based on the size of game board, make scores#.txt, statistics#.txt file if there are no saved scores. if there are saved scores for played board game size, update the file of the size player played.

    ex) play 3*3 game first time, make scores3.txt & statistics3.txt. Then save scores & statistics.

    Thank you :)

    opened by yjh1534 4
  • Project should use gitflow repository management

    Project should use gitflow repository management

    Gitflow-style repos [1] requires a develop branch.

    All forked project's x-feature branches aim to merge with upstream's develop branch. The upstream's repo owner can then merge to the upstream's master branch when "safe and ready" to do so. This method of source-code management may prevent severe merge problems / conflicts in the future.

    1: https://nvie.com/posts/a-successful-git-branching-model/

    enhancement 
    opened by cawvyoct 4
  • CMake corrections: datadir, minimum CMake

    CMake corrections: datadir, minimum CMake

    CMake 3.7 didn't actually work with the project configuration. Put CMake 3.14 (and tested) as a reasonable minimum CMake.

    Corrected data install directory.

    Corrected compiler option selection.

    opened by scivision 0
  • my cmake can't run it

    my cmake can't run it

    when I wtite "ctest -S setup.cmake"in git bash, it shows " Each . represents 1024 bytes of output . Size of output: 0K Error(s) when configuring the project CMake Error at D:/Gitbase/2048.cpp/setup.cmake:53 (message): Configure failed: return -1 cmake return -1 ". But my cmake is newly installed. How to solve this problem? QAQ

    opened by Moon-18 3
  • when load the saved game board, best score is not visible

    when load the saved game board, best score is not visible

      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚ SCORE:                192 โ”‚
      โ”‚ MOVES:                 31 โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚      โ”‚      โ”‚      โ”‚    2 โ”‚
      โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ค
      โ”‚    2 โ”‚      โ”‚      โ”‚    8 โ”‚
      โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ค
      โ”‚      โ”‚    2 โ”‚    4 โ”‚    4 โ”‚
      โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ค
      โ”‚    2 โ”‚    8 โ”‚   32 โ”‚   16 โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    
      W or K or โ†‘ => Up
      A or H or โ† => Left
      S or J or โ†“ => Down
      D or L or โ†’ => Right
      Z or P => Save
    

    Is it normal to not visible the best scorer?

    opened by jungame3757 0
Owner
Mihir Chaturvedi
frontend engineerใƒปcse undergrad @IIIT-Delhiใƒปex @devfolioco, @Project-Betaใƒปand for whatever reason you fancy, i call myself plibither8 ใƒฝ(ยดใƒผ๏ฝ€)
Mihir Chaturvedi
A fully-featured Minecraft server startup script

A fully-featured Minecraft server startup script suite that offers a friendly user interface, blazing fast speeds, and wide compatibility.

null 78 Sep 22, 2022
Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World.

OpenXRay OpenXRay is an improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. S

null 2.1k Oct 2, 2022
Ncurses based omok game, execute omok game in your terminal

omok_game execute omok game in your terminal Omok game played by two people. ํ•œ๊ตญ์–ด ๋ฒ„์ „(korean version)

SunjungAn 1 Sep 3, 2022
A terminal-based Tic-Tac-Toe game for two players, written in C++.

TicTacToe Terminal-based TicTacToe Game Project description A terminal-based Tic-Tac-Toe game for two players, written in C++. Execution Option 1: nav

Sven Eschlbeck 2 Dec 18, 2021
In this repository you'll find the fully reversed source code for GTA III (master branch) and GTA VC (miami branch).

Intro In this repository you'll find the fully reversed source code for GTA III (master branch) and GTA VC (miami branch). It has been tested and work

Zero 1 Nov 11, 2021
Stealthy way to hijack the existing game process handle within the game launcher (currently supports Steam and Battle.net). Achieve external game process read/write with minimum footprint.

Launcher Abuser Stealthy way to hijack the existing game process handle within the game launcher (currently supports Steam and Battle.net). Achieve ex

Ricardo Nacif 77 Sep 25, 2022
Game Boy, Game Boy Color, and Game Boy Advanced Emulator

SkyEmu SkyEmu is low level cycle accurate GameBoy, GameBoy Color and Game Boy Advance emulator that I have been developing in my spare time. Its prima

Sky 211 Sep 29, 2022
MIT Licensed Open Source version of Torque 2D game engine from GarageGames

We've moved! All torque engines have moved to a new organization, Torque Game Engines. Torque2D can be found at https://github.com/TorqueGameEngines/T

GarageGames 1.7k Sep 24, 2022
A simplified version of the famous game Minecraft.

This program uses the concept of the famous game Minecraft but with better graphics. It procedurally generates an infinite world, the player has an animated character and can break blocks, there are also different biomes and mobs.

Angel Uriot 57 Sep 13, 2022
Online version of the greatest card game known to man

10Flips Online version of the greatest card game known to man Client The client is made using Emscripten. Installing # Get the emsdk repo git clone ht

Oskar Mendel 2 Oct 26, 2021
A randomizer for Silent Hill 4: The Room, for the GOG version of the game

A randomizer for Silent Hill 4: The Room, for the GOG version of the game. This does not work for the old PC port and probably never will, there is not really a reason to play the old port these days.

Hunter Stanton 13 Sep 23, 2022
This tool allow you to create / load / edit models used for create a cinematic in game for World of Warcraft 3.3.5 version

CameraCinematic - Discord Introduction This tool allow you to create / load / edit models used for create a cinematic in game for World of Warcraft 3.

Intemporel 9 Mar 14, 2022
A cycle-accurate Game Boy and Game Boy Color Emulator, with rewind feature.

Azayaka is a free and open-source Game Boy and Game Boy Color emulator written in C++. Features Cycle-Accurate emulation. Console based Debugg

Zach Collins 15 Sep 21, 2022
The Game Boy ROM of the Game Boy bitcoin miner!

game-boy-bitcoin-miner The Game Boy ROM of the Game Boy bitcoin miner! To build this, currently this patch needs to be applied to GBDK: https://gist.g

Ghidra Ninja 79 Jul 17, 2022
CLUSEK-RT is a complex game engine written in C++ and the successor of the CLUSEK game engine

CLUSEK-RT is a complex game engine written in C++ and the successor of the CLUSEK game engine. This engine has been designed with a cross-platform design in mind. Thanks to Vulkan API it delivers a next-gen experience with ray tracing to both Linux and Windows platforms

Jakub Biliล„ski 36 Sep 28, 2022
Ground Engine is an easy to use Game Engine for 3D Game Development written in C++

Ground Engine is an easy to use Game Engine Framework for 3D Game Development written in C++. It's currently under development and its creation will b

 PardCode 56 Aug 15, 2022
Minetest is an open source voxel game engine with easy modding and game creation

Minetest is an open source voxel game engine with easy modding and game creation

Minetest 8k Oct 5, 2022
A game made for the Game (Engineless) Jam using Raylib

Fastest Pizza Delivery A fun little 3D game made for the Game (Engineless) Jam. It is still is development but the basic gameplay is something l

Ryuzaki 2 Apr 3, 2022
SameBoy DX is a Qt-based interface of SameBoy, a free, highly accurate Game Boy and Game Boy Color emulator.

SameBoy DX SameBoy DX is a Qt-based interface of SameBoy, a free, highly accurate Game Boy and Game Boy Color emulator. Build requirements: CMake Pyth

Snowy 7 Oct 2, 2022