- Lai, Pok Hang
- Lo, Ian Leong Ting
- Keys:
- Arrow / WASD: Menu bar navigation, snake movement control
- Enter: Select menu option
- Spacebar: Pause
- Snake should move only inside the yellow border and search for food (red apple).
- Once the food was eaten, the snake body grows one unit in length.
- Game ends if the snake crashes with itself or to the wall.
- Try to control the snake to eat as many apples as possible!
- Generation of random game sets or events
- The apples are generated at random (uniformly distributed) around the map.
- mt19937 pseudo-random generator is used.
- Data structures for storing game status
- Class
Snake
, will store all the properties of the current snake. - Class
SaveAndLoad
, for save and load methods.
- Class
- Dynamic memory management
new
operator is used to allocate memory on the free store forSnake
andSaveAndLoad
objects.delete
operator is called to restore the memory allocated when the game ends.
- File input/output
- The pause menu provides the option to save current game status.
- At start menu, the saved game can be loaded from the
log.txt
file, and continue to play. - After the game ends, the score will be recorded in the
leaderboard.txt
file. - Files are saved under
log
directory.
- Program codes in multiple files
./include
contains header files./src
contains source files./log
contains files for saving and loading game status
- Run the following commands in the project root directory
- Install ncurses library and compile the project
make all
- Run the game
./main
make ncurses
will automatically run uponmake all
, it will clone thencurses
library under the project directory (./ncurses
), and install it under your home directory (~/ncurses_files
). Make sure that no non-empty colliding directories exist.- The clone, install and compile process takes around 1-2 minutes when running
make all
the first time. make clean
can remove object files and executable.make clear-score
can clear the game score history.- Fully built and tested on HKU
academy11
server.
ncurses
.
├── Makefile
├── README.md
├── demo
│ ├── demo_1.png
│ ├── demo_2.png
│ ├── demo_3.png
│ └── demo_4.png
├── get_ncurses.sh
├── include
│ ├── new_game.hpp
│ ├── pause_menu.hpp
│ ├── save_and_load.hpp
│ ├── snake.hpp
│ ├── start_menu.hpp
│ └── visuals.hpp
├── log
│ ├── clear-score.sh
│ ├── leaderboard.txt
│ └── state.txt
├── main.cpp
├── ncurses
└── src
├── new_game.cpp
├── pause_menu.cpp
├── save_and_load.cpp
├── snake.cpp
├── start_menu.cpp
└── visuals.cpp