Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Snake Game in Java

🎮 About the Game

This is a classic Snake game built using Java and Swing. The game features smooth movement, food collection, and a score system. The goal is to eat food to grow while avoiding collisions with the snake’s own body. If you crash into yourself, it's Game Over!

🛠️ Features

✅ Smooth and responsive movement ✅ Collision detection with food and snake’s body ✅ Wrap-around mechanics for seamless movement across boundaries ✅ Score tracking ✅ Game restart functionality ✅ Simple and fun gameplay

🚀 How to Run

Prerequisites

  • Java Development Kit (JDK) installed (Java 8 or later)
  • An IDE like IntelliJ IDEA, Eclipse, or VS Code with Java support

Running the Game

  1. Clone this repository
  2. Open the project in your preferred Java IDE.
  3. Compile and run the Main.java file.

🎮 Controls

  • Arrow Keys (⬆️⬇️⬅️➡️): Move the snake in the desired direction
  • Restart Game: Press any key after Game Over

📸 Preview

snake_game_preview

🔧 How it Works

The game is developed using Java Swing and relies on KeyListeners for movement. The core logic includes:

  • Snake movement with queued inputs for smooth direction changes
  • Food placement at random locations
  • Collision detection with walls and itself
  • Score increment when eating food
  • Game-over condition when colliding with itself
  • Game restart when a key is pressed after losing

🏗️ Future Improvements

🔹 More advanced movement mechanics 🔹 Power-ups (e.g., speed boost, invincibility) 🔹 Improved UI with a main menu and settings 🔹 Sound effects and background music

About

Snake game in java made using Java Swing

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages