Skip to content

Snake Game is a simple classic arcade game where the player controls a growing snake to eat food while avoiding collisions with the walls and itself. The game gets progressively challenging as the snake grows longer. ๐Ÿš€๐ŸŽฎ

License

Notifications You must be signed in to change notification settings

JaspreetSingh-exe/Java-SnakeGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Java Snake Game

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.


๐Ÿ“Œ Table of Contents


๐Ÿ•น๏ธ Game Rules

  • 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 ๐Ÿ’€

๐Ÿ› ๏ธ Technologies Used

  • Java 8+
  • Swing & AWT (Java GUI components)
  • Object-Oriented Programming (OOP)
  • Event Handling (KeyListener for controls)

๐Ÿ“š Libraries & Functions

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)

Important Functions

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

๐Ÿ–ฅ๏ธ Game Preview

๐Ÿ Start Screen

Start Screen

๐Ÿ Gameplay

Gameplay

โ˜ ๏ธ Game Over

Game Over Screen


๐Ÿš€ How to Run

Method 1: Run in an IDE (IntelliJ, Eclipse, VS Code)

  1. Clone or download the repository.
  2. Open the project in your preferred IDE.
  3. Compile and run Main.java.

Method 2: Run in Terminal

  1. Open the terminal in the project folder.
  2. Compile the game:
    javac Main.java
  3. Run the game:
     java Main
    

๐Ÿ“ License

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.

About

Snake Game is a simple classic arcade game where the player controls a growing snake to eat food while avoiding collisions with the walls and itself. The game gets progressively challenging as the snake grows longer. ๐Ÿš€๐ŸŽฎ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages