A classic Snake game built using Java, Swing, and AWT for GUI rendering. The game follows traditional mechanics:
- The snake grows when it eats food ๐.
- The game ends if the snake hits the wall or itself.
This project is great for beginners learning Java GUI programming and event handling.
- ๐น๏ธ Game Rules
- ๐ ๏ธ Technologies Used
- ๐ Libraries & Functions
- ๐ฅ๏ธ Game Preview
- ๐ How to Run
- ๐ฏ License
- Use W ๐ก to move Up
- Use S ๐ก to move Down
- Use A ๐ก to move Left
- Use D ๐ก to move Right
- The game ends if the snake:
- Hits the wall ๐ง
- Collides with itself ๐
- Java 8+
- Swing & AWT (Java GUI components)
- Object-Oriented Programming (OOP)
- Event Handling (KeyListener for controls)
The project uses Java's built-in libraries:
| Library | Purpose |
|---|---|
javax.swing.* |
Used for GUI (JFrame, JPanel) |
java.awt.* |
Handles game graphics & rendering |
java.awt.event.* |
Captures keyboard input (KeyListener) |
| Function | Description |
|---|---|
Snake.move() |
Moves the snake based on direction |
Snake.grow() |
Adds a new segment when eating food |
Game.update() |
Checks collisions, food consumption, and updates game state |
Graphics.paintComponent() |
Renders the game on screen |
Food.random_spawn() |
Places food randomly on the grid |
- Clone or download the repository.
- Open the project in your preferred IDE.
- Compile and run
Main.java.
- Open the terminal in the project folder.
- Compile the game:
javac Main.java
- Run the game:
java Main
This project is licensed under the MIT License.
You are free to use, modify, and distribute this software as long as the original license is included.
๐ See the LICENSE file for more details.


