Snake is the common name for a video game concept where the player maneuvers a line which grows in length, with the line itself being a primary obstacle. The concept originated in the 1976 arcade game Blockade, and the ease of implementing Snake has led to hundreds of versions (some of which have the word snake or worm in the title) for many platforms. After a variant was preloaded on Nokia mobile phones in 1998, there was a resurgence of interest in the snake concept as it found a larger audience.
APA - Wikipedia contributors. (2020, March 30). Snake (video game genre). In Wikipedia, The Free Encyclopedia. Retrieved 11:00, May 2, 2020
, from https://en.wikipedia.org/w/index.php?title=Snake_(video_game_genre)&oldid=948244431
Purely implemented using only and only Linked Lists.
No threading or forking used to implement multi-segment body.
- Arch Linux
- Ubuntu Linux
- MacOS
- WSL (Windows Subsystem for Linux)
Make sure that ncurses
library is installed on your system.
- Clone the Repository
- Switch to
master
branch - To build the project, enter
make
. - Run
./snake
. - To remove the program compiled in step 3, enter
make clean
.
-
snake.h
- Contains all the function and variables declaration which are used by all the files. It also contains:struct body
- The body segment of snake.class snake
- A whole single snake.
-
class_snake.cpp
- Contains definitions of functions ofclass snake
. -
functions.cpp
- Contains definitions of functions used inmain.cpp
. Those functions are either declared inmain.cpp
orsnake.h
. -
main.cpp
- The actual logic of forming window, signal handling, printing, etc, is written here.
The division of snake body into segments is explained in snake.h
.
Now let's assume bn means nth body segment. Then linked list of snake, with 2 body segments, looks like:
tail ----> b2 ----> b1 ----> head
The printing starts from tail and a new body segment is pushed from head side.