# Snake 2025 Game [![en](https://img.shields.io/badge/lang-en-red.svg)](https://git.esiee.fr/frequela/snake2025/-/blob/tp6/README.md) [![fr](https://img.shields.io/badge/lang-fr-green.svg)](https://git.esiee.fr/frequela/snake2025/-/blob/tp6/README-fr.md) This project is a simple grid-based snake game using the MLV graphics library. The grid represents a game board with walls, empty spaces, fruits, and a snake. The program displays the grid in a graphical window and waits for user interaction. ## Features - Displays a grid with walls, empty spaces, fruits, and a snake. - Uses the MLV graphics library for graphical rendering. - Ensures that blocks outside the grid are displayed as black. - Allows the user to quit the program by pressing the ESC key. - Implements a dynamic snake using a linked list for its segments. - Handles snake movement by updating the head position and shifting all segments accordingly. - Supports snake growth when eating fruits. ## Grid Representation - The grid is represented as a 2D array of characters: - `'w'` for walls. - `' '` (space) for empty spaces. - `'f'` for fruits. - `'s'` for the snake. ## Snake Representation - The snake is implemented as a linked list of segments (`Position` structures), where: - Each segment has `x` and `y` coordinates. - The `next` pointer links to the next segment in the snake. - The snake's movement is handled by: - Adding a new head based on the current direction. - Shifting all segments to follow the head. - Removing the tail unless the snake eats a fruit. ## Dependencies - GCC (GNU Compiler Collection) - MLV (Mini Library for Visualization) ## Installation ### Installing MLV on Ubuntu 1. Update your package list and install the required packages: ```sh sudo apt-get update sudo apt-get install build-essential gcc make libmlv3-dev ``` ### Building the Program 1. Clone the repository or download the source code. 2. Navigate to the directory containing the `Makefile`. 3. Run the following command to build the program: ```sh make ``` This will compile the source files and create an executable named `game` in the `build` directory. ## Usage 1. After building the program, run the executable: ```sh ./game ``` 2. A window will open displaying the grid. Blocks outside the grid will appear black. Use the arrow keys to control the snake. Press the ESC key to close the window. ## Game Logic - **Snake Movement**: - The snake moves in the current direction, updating its head position and shifting all segments. - If the snake eats a fruit, it grows by adding a new segment without removing the tail. - If the snake collides with a wall or itself, the game ends. - **Grid Updates**: - The grid is updated to reflect the snake's new position after each move. - Fruits are removed from the grid when eaten by the snake. - **Winning Condition**: - The player wins when all fruits on the grid are collected. - **Losing Condition**: - The game ends if the snake collides with a wall or itself. ## Cleaning Up To clean up the build files, run: ```sh make clean ``` This will remove the object files and the executable. ## License This project is licensed under the GPLv3 License. For more details, see [GPLv3 License](https://www.gnu.org/licenses/gpl-3.0.en.html). ## Authors - Alex Frequelin (light_emerald@aostia.com) ## Acknowledgments - Adrien Boussicault and Marc Zipstein for the MLV library. - ESIEE Paris for the course materials and guidance.