|
1 | | -# Snake Game 🐍 |
| 1 | +# 🐍 Snake Game |
2 | 2 |
|
3 | | -Welcome to **Snake**, a classic arcade game where you guide a growing snake to eat fruits and avoid obstacles. This project is an implementation of the iconic game in Python, developed with object-oriented programming principles. |
| 3 | +Welcome to **Snake**, a classic arcade game implementation in Python. Navigate the snake, eat fruits to grow, and avoid obstacles in this project built with Object-Oriented Programming (OOP) principles. |
4 | 4 |
|
5 | | -## 📜 Table of Contents |
6 | | - |
7 | | -- [Features](#features) |
8 | | -- [Installation](#installation) |
9 | | -- [Usage](#usage) |
10 | | -- [Images](#images) |
11 | | -- [File Structure](#file-structure) |
12 | | -- [Technologies](#technologies) |
13 | | -- [Contributing](#contributing) |
14 | | -- [About This Project](#about) |
15 | | -- [License](#license) |
16 | | -- [Security](#security) |
17 | | -- [Code of Conduct](#code-of-conduct) |
18 | | - |
19 | | - |
20 | | -## 🕹️ Features <a name="features"></a> |
| 5 | +# 📸 Demo |
| 6 | +<div style="display: flex; gap: 10px;"> |
| 7 | + <img alt="Snake Gameplay" src="img/snake.png" width="350px"> |
| 8 | + <img alt="Game Over Screen" src="img/gameover.png" width="350px"> |
| 9 | +</div> |
21 | 10 |
|
22 | | -- Classic Snake gameplay with growing tail |
23 | | -- Multiple levels with increasing difficulty and obstacles |
24 | | -- Random fruit generation |
25 | | -- Game-over conditions for colliding with obstacles, walls, or the snake's own tail |
26 | | -- Graphical interface with intuitive keyboard controls |
| 11 | +# 📍 Table of Contents |
| 12 | +- [📝 Description](#-description) |
| 13 | + - [🧩 Key Features](#-key-features) |
| 14 | + - [🧱 Project Structure](#-project-structure) |
| 15 | + - [🛠️ Technologies](#️-technologies) |
| 16 | +- [🚀 Getting Started](#-getting-started) |
| 17 | + - [📋 Prerequisites](#-prerequisites) |
| 18 | + - [⚙️ Installation](#️-installation) |
| 19 | +- [💡 Usage](#-usage) |
| 20 | +- [🤝 Contributing](#-contributing) |
| 21 | +- [📄 License](#-license) |
| 22 | + |
| 23 | +# 📝 Description |
| 24 | +This project was developed as a university assignment to demonstrate the use of classes, inheritance, and modular logic in Python. It uses a custom library for graphical rendering and event handling. |
| 25 | + |
| 26 | +## 🧩 Key Features |
| 27 | +- **Levels & Difficulty:** Multiple levels with increasing speed and strategic obstacles. |
| 28 | +- **Classic Mechanics:** Growing tail system and random fruit spawning. |
| 29 | +- **Collision Logic:** Advanced detection for walls, obstacles, and self-collision. |
| 30 | +- **Pause System:** Ability to pause the game at any moment. |
| 31 | + |
| 32 | +## 🧱 Project Structure |
| 33 | +```text |
| 34 | +Snake/ |
| 35 | +├── graphics/ # Rendering libraries (gamelib & custom) |
| 36 | +├── img/ # Demo screenshots |
| 37 | +├── resources/ # Configuration files (obstacles.txt) |
| 38 | +├── src/ # Core game logic (OOP classes) |
| 39 | +│ ├── snake.py |
| 40 | +│ ├── fruit.py |
| 41 | +│ └── game.py |
| 42 | +└── main.py # Entry point |
| 43 | +``` |
27 | 44 |
|
28 | | -## 🚀 Installation <a name="installation"></a> |
| 45 | +## 🛠️ Technologies |
| 46 | +* **Python 3.x** |
| 47 | +* **Gamelib**: A lightweight thread-based rendering library for Python interfaces. |
29 | 48 |
|
30 | | -To run this project locally, follow these steps: |
| 49 | +# 🚀 Getting Started |
| 50 | +## 📋 Prerequisites |
| 51 | +* Python 3.10 or higher installed on your system. |
31 | 52 |
|
| 53 | +## ⚙️ Installation |
32 | 54 | 1. Clone the repository: |
33 | 55 | ```bash |
34 | | - git clone https://github.com/SebaB29/Snake.git |
35 | | - ``` |
36 | | - |
37 | | -2. Navigate to the project directory: |
38 | | - ```bash |
| 56 | + git clone [https://github.com/SebaB29/Snake.git](https://github.com/SebaB29/Snake.git) |
39 | 57 | cd Snake |
40 | 58 | ``` |
41 | | - |
42 | | -3. Run the game: |
| 59 | +2. (Optional) Create a virtual environment: |
43 | 60 | ```bash |
44 | | - python main.py |
| 61 | + python -m venv venv |
| 62 | + source venv/bin/activate # On Windows: venv\Scripts\activate |
45 | 63 | ``` |
46 | 64 |
|
47 | | -## 🎮 Usage <a name="usage"></a> |
48 | | - |
49 | | -Use the following controls to play the game: |
50 | | - |
51 | | -- **Left Arrow**: Move left |
52 | | -- **Right Arrow**: Move right |
53 | | -- **Up Arrow**: Move up |
54 | | -- **Down Arrow**: Move down |
55 | | -- **P**: Pause |
56 | | - |
57 | | -Avoid obstacles and eat fruits to grow longer! |
58 | | - |
59 | | -## 📷 Images <a name="images"></a> |
60 | | - |
61 | | -<div style="display: flex;"> |
62 | | - <img alt="Img Snake" src="img/snake.png" width="400px" height="400px"> |
63 | | - <img alt="Img Game Over" src="img/gameover.png" width="400px" height="400px"> |
64 | | -</div> |
65 | | - |
66 | | -## 📁 File Structure <a name="file-structure"></a> |
67 | | - |
68 | | -The project structure is as follows: |
69 | | - |
| 65 | +# 💡 Usage |
| 66 | +To start the game, simply run the main script: |
| 67 | +```bash |
| 68 | +python main.py |
70 | 69 | ``` |
71 | | -Snake/ |
72 | | -├── .github/ |
73 | | -│ ├── CODE_OF_CONDUCT.md |
74 | | -│ ├── CONTRIBUTING.md |
75 | | -│ ├── SECURITY.md |
76 | | -│ ├── ISSUE_TEMPLATE/ |
77 | | -│ │ ├── bug_report.md |
78 | | -│ │ └── feature_request.md |
79 | | -│ └── PULL_REQUEST_TEMPLATE.md |
80 | | -├── graphics/ |
81 | | -│ ├── game_render.py |
82 | | -│ └── gamelib.py |
83 | | -├── img/ |
84 | | -│ └── [2 demo images of the game] |
85 | | -├── resources/ |
86 | | -│ └── obstacles.txt |
87 | | -├── src/ |
88 | | -│ ├── constant.py |
89 | | -│ ├── event_controller.py |
90 | | -│ ├── fruit.py |
91 | | -│ ├── game.py |
92 | | -│ ├── obstacle_loader.py |
93 | | -│ ├── obstacle.py |
94 | | -│ ├── program.py |
95 | | -│ └── snake.py |
96 | | -├── .gitignore |
97 | | -├── LICENSE |
98 | | -├── main.py |
99 | | -└── README.md |
100 | | -``` |
101 | | - |
102 | | -- **graphics/**: Contains libraries for rendering the game (gamelib and custom graphics). |
103 | | -- **img/**: Includes demo images showcasing the game's functionality. |
104 | | -- **resources/**: Contains the obstacles configuration file (`obstacles.txt`). |
105 | | -- **src/**: Includes source code files for game logic (snake, fruit, obstacles, and game flow). |
106 | | -- **main.py**: The entry point of the application. |
107 | | - |
108 | | -## 🛠️ Technologies <a name="technologies"></a> |
109 | | - |
110 | | -This project is built with: |
111 | | - |
112 | | -- Python |
113 | | -- [Gamelib](https://github.com/dessaya/python-gamelib) (A library created by the instructor to facilitate the use of threads and rendering for the interface) |
114 | | - |
115 | | -## 🤝 Contributing <a name="contributing"></a> |
116 | | - |
117 | | -Contributions are welcome! If you'd like to improve the game, feel free to fork the repository and submit a pull request. |
118 | | - |
119 | | -1. Fork the repository |
120 | | -2. Create your feature branch (`git checkout -b feature/AmazingFeature`) |
121 | | -3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) |
122 | | -4. Push to the branch (`git push origin feature/AmazingFeature`) |
123 | | -5. Open a pull request |
124 | | - |
125 | | -## 📚 About This Project <a name="about"></a> |
126 | | - |
127 | | -This project was developed as a practical assignment for university. It aims to implement the classic Snake game using Python, focusing on game logic and graphical interface through object-oriented programming principles. |
128 | | - |
129 | | -## 📄 License <a name="license"></a> |
130 | | - |
131 | | -Distributed under the MIT License. See `LICENSE` for more information. |
132 | | - |
133 | | -## 🔐 Security <a name="security"></a> |
134 | | - |
135 | | -If you discover a vulnerability, please review our [Security Policy](.github/SECURITY.md) for guidance on reporting. |
136 | | - |
137 | | -## 📜 Code of Conduct <a name="code-of-conduct"></a> |
138 | 70 |
|
139 | | -Please read our [Code of Conduct](.github/CODE_OF_CONDUCT.md) to understand expected behavior. |
| 71 | +## 🎮 Controls |
| 72 | +| Key | Action | |
| 73 | +|-------------|----------------| |
| 74 | +| Arrow Up | Move Up | |
| 75 | +| Arrow Down | Move Down | |
| 76 | +| Arrow Left | Move Left | |
| 77 | +| Arrow Right | Move Right | |
| 78 | +| P | Pause / Resume | |
| 79 | + |
| 80 | +# 🤝 Contributing |
| 81 | +1. Fork the project. |
| 82 | +2. Create your Feature Branch (git checkout -b feature/AmazingFeature). |
| 83 | +3. Commit your changes (git commit -m 'Add some AmazingFeature'). |
| 84 | +4. Push to the Branch (git push origin feature/AmazingFeature). |
| 85 | +5. Open a Pull Request. |
| 86 | + |
| 87 | +# 📄 License |
| 88 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments