plibither8 / 2048.cpp Goto Github PK
View Code? Open in Web Editor NEW๐ฎ Fully featured terminal version of the game "2048" written in C++
License: MIT License
๐ฎ Fully featured terminal version of the game "2048" written in C++
License: MIT License
Currently, users have to follow 6 steps to install and run 2048. Though these are small and can be done quickly, it would be much more convenient if we have a bash script that does this for us.
The bash script will do the following:
home
folder.mkdir build
, cd build
to create the build directory.cmake ..
and make
to create the final, executable program.These are the 3 main steps that the script will follow. After this, we should add the 2048
program to the PATH
so that users can access the game from anywhere in their terminal.
Either adding to the PATH
permanently or adding an alias to the game in their .bashrc
or .zshrc
files.
With the bash script we can also now handle OS specific actions, as adding to the PATH
will be quite different in all the three major OSs.
#using html and make website for University and college.
Project could use clang-format for formatting the source code so that it would be more generic across different contributors. More information here: https://clang.llvm.org/docs/ClangFormat.html
Instead of exit application.
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!
enum class
is a new C++ 11 feature and it has several advantages over enum
, more detail here https://isocpp.org/wiki/faq/cpp11-language-types#enum-class
I fixed Color
(#62) but later found more in other places. It isn't high priority but a good reason for refactoring code :)
I feel like the current structure of files and directories is inefficient and not clean. There should be better management of the source files and the build files, rather than all of them being in the root directory.
I am comparatively inexperienced with how larger C++ projects handle directory management. It would be great if a better management is suggested, and better yet, I'd welcome all PRs that implement such a structure. Thanks.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ 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?
A (toplevel) .clang-format
file would help developers clean up pre-committed source code before making PRs.
First of all, ๐ for awesome project!
One cool aspect of 2048 is derivatives, such as merging elements to get element with higher atomic number. Let's add support for such themes!
Steps to reproduce:
I'll work on this.
Rather than having to ctrl+c
to end the current game in progress, there could be an option to forfeit/quit the current game and return to menu.
I've noticed that there is already an CODE_HOTKEY_QUIT_ENDLESS_MODE
that is somewhat similar to the proposed idea, but as far as I could tell, the endless mode is not yet implemented (is that right?).
Add Travis CI as an automated pre-check to help accept and merge all Pull Requests.
To prevent future incomplete and correctional merge requests, an automated Travis CI check would be very helpful.
This used to be available for pull requests in the project however this feature seems to have been lost / changed?
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.
cd src & g++ *.cpp -o 2048 -I ./headers
After I finish a game, the final statistics displayed and stored do not match my final score. The final score is always stored as 0, and the largest tile is always stored as 2. Number of moves is always stored as -1. Time taken is stored correctly.
To recreate this error:
Clone the git repo, install it to a local prefix, run the game, select new game, and lose a game.
Compiled from git master 81c0eeb
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SCORE: 1156 โ
โ BEST SCORE: 1156 โ
โ MOVES: 127 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโฌโโโโโโโฌโโโโโโโฌโโโโโโโ
โ 2 โ 4 โ 32 โ 4 โ
โโโโโโโโผโโโโโโโผโโโโโโโผโโโโโโโค
โ 4 โ 8 โ 4 โ 2 โ
โโโโโโโโผโโโโโโโผโโโโโโโผโโโโโโโค
โ 8 โ 2 โ 128 โ 8 โ
โโโโโโโโผโโโโโโโผโโโโโโโผโโโโโโโค
โ 16 โ 32 โ 2 โ 16 โ
โโโโโโโโดโโโโโโโดโโโโโโโดโโโโโโโ
Game over! You lose.
STATISTICS
โโโโโโโโโโ
Final score: 0
Largest Tile: 2
Number of moves: -1
Time taken: 37s
Hmm, not really correct.
It should be:
Final score: 1156
Largest Tile: 128
Number of moves: 127
And this is what shows up for View Highscores and Statistics
:
SCOREBOARD
โโโโโโโโโโ
โโโโโโโฌโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ No. โ Name โ Score โ Won? โ Moves โ Largest Tile โ Duration โ
โโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโค
โ 1. โ kc โ 0 โ No โ -1 โ 2 โ 9m 22s โ
โ 2. โ kc โ 0 โ No โ -1 โ 2 โ 37s โ
โโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโดโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
STATISTICS
โโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ Best Score โ 0 โ
โ Game Count โ 2 โ
โ Number of Wins โ 0 โ
โ Total Moves Played โ 18446744073709551614 โ
โ Total Duration โ 9m 59s โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
When I finish the installation and open the game, the coding seems to have some problems. Can you help me? Environment: Windows 10, MinGW.
้นๅฑธๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น?
้น?SCORE: 0 ้น?
้น?MOVES: 0 ้น?
้นๆบๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น?
้นๅฑธๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น๎ฝๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น๎ฝๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น?
้น? 2 ้น? ้น? ้น?
้นๆบพๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นๅฐๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นๅฐๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น?
้น? ้น? ้น? ้น?
้นๆบพๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นๅฐๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้นๅฐๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น?
้น? ้น? 2 ้น? ้น?
้นๆบๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น็ฒนๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น็ฒนๆข้นโฌ้นโฌ้นโฌ้นโฌ้นโฌ้น?
W or K or ้ซ?=> Up
A or H or ้ซ?=> Left
S or J or ้ซ?=> Down
D or L or ้ซ?=> Right
Z or P => Save
Sorry about the CI failure on the new github actions. I know it went wrong and I'll make a new PR to fix it in the next couple days thank you.
I'm trying to compile this on Fedora, but it is failing.
/tmp/ccv0qRho.o: In function `main':
2048.cpp:(.text+0x26): undefined reference to `Menu::startMenu(int)'
collect2: error: ld returned 1 exit status
Basically user can go back to menu at anytime and can choose to exit application nicely instead of Ctrl+C
.
There is a empty directory in source tree named build. there is nothing in it except an empty file. I strongly recommend to remove this directory.
Hi, we have 2048.cpp in MacPorts and it builds fine on OS X 10.11 and later, but on OS X 10.10 it fails to build. There are many errors in the log but the first is:
src/game-pregamemenu.cpp:139:42: error: no viable overloaded '='
std::tie(loaded_gameboard, tempGBoard) =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/tuple:500:29: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'tuple<bool, struct GameBoard>' to 'tuple<std::initializer_list<bool> &, Game::GameBoard &>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY tuple
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/tuple:500:29: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'tuple<bool, struct GameBoard>' to 'const tuple<std::initializer_list<bool> &, Game::GameBoard &>' for 1st argument
class _LIBCPP_TYPE_VIS_ONLY tuple
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/tuple:692:26: note: candidate template ignored: disabled by 'enable_if' [with _Tuple = std::__1::tuple<bool, Game::GameBoard>]
__tuple_assignable<_Tuple, tuple>::value
^
STATISTICS
----------
Final score: 11408
Largest Tile: 1024
Number of moves: 692
Time taken: 1068.8 seconds
I think Time taken
change to xx Hours xx Minutes xx Seconds can be more acceptable by human beings.
std::endl
is used everywhere while you should use \n
instead of.
Hi,
I am a total noob at C++ and I am using your project to experiment with the language. Reading the source code I came across this recursive call on Game::startGame
which felt suspicious to me:
Line 420 in 371bee7
I thought this recursive strategy may cause a stack overflow if abused, for example like this:
$ yes 1 | build/2048.out > /dev/null 2>&1
[1] 28385 broken pipe yes 1 |
28386 segmentation fault (core dumped) build/2048.out > /dev/null 2>&1
I don't think this is an important issue but I'd like to know why you used this strategy instead of a loop.
Thank you for the project it has been a very helpful resource to me.
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?
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
โถ ./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 |
+--------------------+------------+
We should be storing the game data in some centralised folder like/usr/lib/2048/
.
๐บ๏ธ Many people around the world enjoy 2048.cpp ๐๏ธ
However, English may not be the native language of many players.
The game should have some basic multilingual support so other players around the world:
When I have to shut down my computer or do other jobs but I haven't finished the game, I do NOT want to give up the game, I need to save the game intermediate progress. I think it's important!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.