Here on blog what else is content about graphics for terminal(TUI, Terminal User Interface) and command line, this blog lives up to its name ๐ .
And today we are going to increase this content by indicating some games and animations in the terminal that serve for purposes such as: fun, learning and studying the source code.
And in this case, we will indicate 4 software written in C++ that have an easy to understand code.
Letโs go to these 4 tips!
2048 is a puzzle game created in March 2014 by Italian developer Gabriele Cirulli, in which the objective is to slide numbered pieces in a grid, combining them and create a tile with the number 2048.
2048.cpp is the version of this game written in C++ . To compile you will need the following tools:
After having the compile-time dependencies, now just clone, build and install with the following commands:
After generating the binary, you can now play it! Just run:
On the first screen displayed, choose the desired option, that is, for a new game, press the number 1 and then press Enter .
Then define the number of rows and columns of the game that somehow represents the level of difficulty, the minimum value is 3 (three) . For example, press 4(zero) and then press Enter and the game will start:
The mini tutorial for use can be found on the game screen itself:
If you want to exit the game press Ctrl + C .
To install just move this binary to some path contained in your $PATH
variable, example:
Then remove the cloned directory:
And then when you want to play it, just run the command 2048
in the terminal.
There is an option to compile with Meson for more information see repository .
Also know another alternative to 2048.cpp a 2048 made in C: 2048-in-terminal.
Flappy Bird is a game initially developed for mobile by Vietnamese programmer Dong Nguyen.
The game is a side-scroller where the player controls a bird, trying to fly between columns of green pipes without hitting them.
Ascii Bird is a game based on Flappy Bird made with the library NCURSES created using only the characters from the table ASCII.
You will need the following tools to be able to build on your system:
After that run the commands:
And to test, just run: ./flap
.
The game will automatically load after the similar animation below:
After that it will automatically start, use the up โ and down โ directional keys to move the player.
To install just move this binary to some path contained in your $PATH
variable, example:
And when you want to play run:
flap
in the terminal . For more information see the repository .
Pong is a two-dimensional sports game that simulates table tennis. The player controls an in-game racket by moving it vertically across the screen.
They can compete against another player by controlling a second racket on the opposite side. Players use the paddles to hit a ball back and forth. The objective is for each player to reach eleven points before the opponent; Points are earned when one fails to return the ball to the other.
Pong was manufactured by Atari and originally released in 1972. It was one of the first successful arcade video games in the world.
There are several remakes of Pong, one of them is Pong written in C++ and NCURSES .
To install, remember to have the build dependencies: Git, g++ and GNU Make .
To install, run:
After compiled, run: ./pong
and use the keys w, a, s and d for player 1 and โ, โ, โ and โ for player 2 to play. For more information visit the repository .
An alternative to this Pong is the PongC made in C that can be accessed here .
ASCII Rain is an animation of rain in the terminal.
You will ask:
โ Why the hell do I want to watch rain in the terminal?
Well, this is really a legitimate question, but there is a culture called: unixporn who like to use these resources to improve their rice (term used to represent the combination of desktop environment customizations in a different way).
We have some articles in this regard and for more information click this link .
If you want to reproduce this rain in the terminal, install the dependencies(git
, gcc
and make
). And then clone:
Compile:
Run and/or install:
Result:
For more information visit the repository .
You noticed that almost all the applications we install in the system directory: /usr/local/bin
and for that we need to use sudo
.
Although thereโs this in several tutorials on this blog including this article, I particularly donโt recommend it for security and organization reasons.
Install them only for your user, that is, isolating a little more.
For all cases do the following:
Then add that directory to your $PATH
variable:
To Bash
Close and then open your terminal or just run the commands below:
And every time you need to install a third-party application use this directory, for example:
And instantly the command is already available in your terminal.
Better, right? ๐
cpp cppdaily terminal unixporn