Simple Pong game on C language for terminal Linux.
ncurses
- for real-time mode
Installing the ncurses library in Debian/Ubuntu Linux:
$ sudo apt install ncurses-bin
unistd
- for the delay between cards in microsecondsstdio
- for other primitive actions (e. g. printf())
Go to the Pong-game folder and enter in the terminal:
$ make
Compiled by Pong_game. Run Pong_game in the terminal:
$ ./Pong_game
To move the left racket, use the keys 'A'
and 'Z'
('a' and 'z'), for the right - 'K'
and 'M'
('k' and 'm'). To pause the game, you need to press the space
bar. To exit the game, you need to press ESC
or wait for one of the players to win. In the game you can change the speed using the keys '1'
, '2'
, '3'
, .. ,'0'
.
With standard settings, the game ends when one of the players scores seven points.
Since only one input stream is used, when holding the control keys of the racket or when pressing intensively, the racket can move for some time by "inertia".
If you want to change drawing symbols, size of field, control keys or the final score to win, you can do it in constants.h.
Drawing management
#define SCORE_WIN 7
#define RACKET_LEFT ']'
#define RACKET_RIGHT '['
#define FIELD ' '
#define WALL '='
#define BALL 'o'
#define MIDDLE_WALL '|'
#define FRAME '-'
#define Y_MAX 20
#define X_MAX 80
Game management
#define EXIT 27 // ESC
#define PAUSE 32 // SPACE
#define UP_RACKET_LEFT 'A'
#define DOWN_RACKET_LEFT 'Z'
#define UP_RACKET_RIGHT 'K'
#define DOWN_RACKET_RIGHT 'M'