This is a classic Snake game implemented in Java using Swing GUI components (JFrame, JPanel, Timer, etc.). The player controls a snake that grows in length by eating food. The game ends if the snake collides with itself or the wall.
- Control the snake using arrow keys.
- Eat the food (randomly appearing).
- Each food increases the snakeโs length and score.
- Avoid crashing into the wall or the snakeโs own body.
- Java SE (8+)
- Swing (GUI)
- AWT (for graphics and event handling)
- Real-time movement using Timer and key listeners.
- Score system based on how much food is eaten.
- Collision detection (walls & self).
- Restart functionality.
- Java Swing-based GUI using:
- JFrame (main window)
- JPanel (game area)
- Graphics (drawing snake, food, score)
-
Snake starts moving in a direction.
-
Player controls it using arrow keys (up, down, left, right).
-
If snake eats food:
Grows longer.
Score increases.
New food is generated randomly.
-
If snake hits:
Wall or itself โ game over.
Press R to restart after game over.
๐ GitHub: https://github.com/pratikkhot100
๐ผ LinkedIn: https://www.linkedin.com/in/pratikkhot01
๐ง Email: pratikkhot1207@gmail.com