A classic Snake Game implementation in Java using Swing for GUI. This project demonstrates Object-Oriented Programming principles and basic game development concepts.
- Complete Snake game with intuitive controls
- Object-Oriented design with separate classes for game components
- Score tracking
- Game over screen with restart option
- Clean, readable code with comments
- Java
- Swing (for GUI)
- OOP principles
-
Controls:
- Use the arrow keys (↑, ↓, ←, →) to control the snake's direction
- Press space to restart the game after game over
-
Game Rules:
- Eat the red food to grow and earn points
- Avoid hitting the walls or your own tail
- The game gets progressively faster as your score increases
- Java Development Kit (JDK) 8 or higher
- Any Java IDE (IntelliJ IDEA recommended)
-
Clone the repository:
git clone https://github.com/yourusername/snake-game.git
-
Open the project in your IDE
-
Run the main class
SnakeGame.java
Alternatively, you can compile and run from the command line:
javac SnakeGame.java
java SnakeGameSnakeGame.java- Main class with JFrame setupGamePanel.java- The game panel where the game is renderedSnake.java- Class representing the snake with its properties and behaviorsFood.java- Class representing the food itemsDirection.java- Enum for snake's direction
This project demonstrates:
- Implementation of game loops using Swing Timer
- Handling user input in Java applications
- Collision detection algorithms
- Basic game state management
- Object-Oriented design principles
- Based on the classic Snake game
- Created as an educational project to teach Java programming
- Special thanks to IntelliJ IDEA for their excellent Java development environment
Feel free to fork this project and make your own improvements.
