Skip to content

bibekchandsah/snake-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Snake Game - Java Edition

A modern, feature-rich Snake Game built with Java Swing, featuring multiple difficulty levels, special food varieties, high score tracking, and emoji support!

๐Ÿ“ธ Screenshots

Welcome Screen Welcome screen with game instructions

Gameplay Active gameplay with special food and score tracking

Game Over Game over screen showing final score and high score

๐ŸŽฎ Download & Play

Quick Start (Windows)

Download SnakeGame.exe

Simply download and double-click to play! No installation required.

Note: Requires Java Runtime Environment (JRE) 8 or higher installed on your system.

Alternative Download

๐Ÿ“‹ System Requirements

  • Operating System: Windows 7/8/10/11, Linux, or macOS
  • Java: JRE 8 or higher (Download Java)
  • RAM: 256 MB minimum
  • Disk Space: 50 MB
  • Display: 800x600 resolution or higher

๐Ÿ“ธ Features

๐ŸŽฎ Gameplay Features

  • Classic Snake Gameplay - Control the snake, eat food, and grow longer
  • Smooth Controls - Responsive arrow key controls
  • Multiple Difficulty Levels - Easy, Medium, and Hard modes with adjustable speeds
  • Wall Collision Toggle - Choose between classic mode (walls kill) or wrap-around mode
  • Pause/Resume - Pause the game anytime with the Pause button

๐ŸŽ Food Varieties

  1. ๐ŸŽ Normal Apple (Red) - Worth 1 point
  2. โญ Golden Apple (Gold) - Worth 5 points, appears every 15 seconds
  3. ๐Ÿ’Ž Bonus Diamond (Purple) - Worth 3 points, disappears after 5 seconds!
  4. โšก Speed Boost (Blue) - Worth 1 point + 40% speed increase for 5 seconds

๐Ÿ† Score System

  • Real-time Score Display - Track your current score
  • High Score Tracking - Automatically saves your best score
  • Persistent Storage - High scores saved between game sessions
  • New High Score Celebration - Special notification when you break records

๐ŸŽจ Visual Features

  • Clean UI - Dark theme with colorful elements
  • Emoji Support - Full emoji rendering for food and messages
  • Glow Effects - Special foods have glowing auras
  • Score Panel - Dedicated panel below game board showing stats
  • Countdown Timers - Visual timer for bonus food and speed boosts

๐Ÿš€ How to Run

Option 1: Run the Executable (Easiest - Windows Only)

  1. Download SnakeGame.exe from Releases
  2. Double-click the downloaded file
  3. Play! ๐ŸŽฎ

Option 2: Run the JAR File (All Platforms)

  1. Make sure Java is installed: java -version
  2. Download SnakeGame.jar from Releases
  3. Run: java -jar SnakeGame.jar

Option 3: Build from Source

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Git (optional)

Clone Repository

git clone https://github.com/bibekchandsah/snake-game.git
cd snake-game

Compilation

javac SnakeGame.java GamePanel.java SettingsPanel.java HighScoreManager.java Food.java

Run

java SnakeGame

Build Executable (Windows)

See BUILD.md for detailed instructions on creating the EXE file.

๐ŸŽฏ How to Play

Controls

  • โฌ†๏ธ Up Arrow / W - Move Up
  • โฌ‡๏ธ Down Arrow / S - Move Down
  • โฌ…๏ธ Left Arrow / A - Move Left
  • โžก๏ธ Right Arrow / D - Move Right

Supports both Arrow Keys and WASD keys for movement!

Game Rules

  1. Click the Start button to begin
  2. Use arrow keys to control the snake
  3. Eat food to grow and earn points
  4. Avoid hitting yourself (self-collision = game over)
  5. If wall collision is enabled, avoid hitting walls

Settings

  • Difficulty Levels:

    • ๐ŸŸข Easy - 150ms delay (slower, easier to control)
    • ๐ŸŸก Medium - 100ms delay (moderate speed)
    • ๐Ÿ”ด Hard - 50ms delay (fast-paced challenge)
  • Wall Collision:

    • โœ… ON - Snake dies when hitting walls (classic mode)
    • โฌœ OFF - Snake wraps to opposite side (endless mode)

๐Ÿ“ Project Structure

snake-game/
โ”œโ”€โ”€ SnakeGame.java          # Main application entry point
โ”œโ”€โ”€ GamePanel.java          # Core game logic and rendering
โ”œโ”€โ”€ SettingsPanel.java      # UI controls (difficulty, settings, buttons)
โ”œโ”€โ”€ HighScoreManager.java   # High score persistence manager
โ”œโ”€โ”€ Food.java              # Food types and properties
โ”œโ”€โ”€ icon.ico               # Application icon
โ”œโ”€โ”€ highscore.dat          # Saved high score (auto-generated)
โ”œโ”€โ”€ preview1.png           # Welcome screen screenshot
โ”œโ”€โ”€ preview2.png           # Gameplay screenshot
โ”œโ”€โ”€ preview3.png           # Game over screenshot
โ”œโ”€โ”€ README.md              # This file
โ””โ”€โ”€ BUILD.md               # Build instructions for EXE

๐ŸŽฏ Releases

Download the latest version from the Releases page:

  • SnakeGame.exe - Windows executable with custom icon
  • SnakeGame.jar - Cross-platform JAR file
  • Source code - ZIP and TAR.GZ archives

๐Ÿ› ๏ธ Technical Details

Technologies Used

  • Java - Core programming language
  • Java Swing - GUI framework
  • AWT Graphics - 2D graphics rendering
  • Timer - Game loop mechanism
  • File I/O - High score persistence

Key Classes

SnakeGame.java

  • Main window setup
  • Integrates GamePanel and SettingsPanel

GamePanel.java

  • Game board rendering (600x600 pixels)
  • Snake movement and collision detection
  • Food spawning and management
  • Score tracking and display

SettingsPanel.java

  • Difficulty selection (radio buttons)
  • Wall collision toggle (checkbox)
  • Start/Pause/Resume button
  • Auto-updates button states

HighScoreManager.java

  • Loads high score from file on startup
  • Saves new high scores automatically
  • Persistent storage using highscore.dat

Food.java

  • Four food types with different properties
  • Point values and visual effects
  • Timed expiration for bonus food
  • Speed boost functionality

๐ŸŽจ Color Scheme

  • Background: Black (#000000)
  • Snake Head: Bright Green (#00FF00)
  • Snake Body: Dark Green (#2DB400)
  • Grid: Dark Gray (#191919)
  • Normal Food: Red (#FF0000)
  • Golden Food: Gold (#FFD700)
  • Bonus Food: Purple (#8A2BE2)
  • Speed Food: Deep Sky Blue (#00BFFF)
  • High Score: Yellow (#FFFF00)
  • Score Panel: Dark Gray (#1E1E1E)

๐Ÿ“Š Scoring

Food Type Points Frequency Duration Effect
๐ŸŽ Normal Apple 1 Common Permanent None
โญ Golden Apple 5 Every 15s Permanent None
๐Ÿ’Ž Bonus Diamond 3 Every 20s 5 seconds Disappears
โšก Speed Boost 1 10% chance Permanent +40% speed for 5s

๐ŸŽฏ Game Strategy Tips

  1. Focus on Survival - Don't rush for golden apples if it's risky
  2. Plan Your Route - Think ahead to avoid trapping yourself
  3. Use Wrap Mode - Disable wall collision for easier gameplay
  4. Speed Boosts - Be extra careful when speed boost is active
  5. Bonus Food - Rush for purple diamonds before they vanish!
  6. High Scores - Try different difficulty levels to maximize points

๐Ÿ› Known Limitations

  • Game speed doesn't progressively increase with score
  • No sound effects or background music
  • Single-player only
  • Fixed board size (600x600)

๐Ÿš€ Future Enhancements (Planned)

  • Sound effects and background music
  • Progressive difficulty (auto-speed increase)
  • Multiple themes/skins
  • Leaderboard with top 10 scores
  • Obstacles and maze mode
  • Two-player mode
  • Achievement system
  • Game statistics tracking
  • Mobile/touch controls support

๐Ÿ“ Version History

Version 1.0 (Current)

  • โœ… Classic snake gameplay
  • โœ… Three difficulty levels
  • โœ… Wall collision toggle
  • โœ… High score system with file persistence
  • โœ… Four food varieties with special effects
  • โœ… Emoji support
  • โœ… Pause/Resume functionality
  • โœ… Welcome screen
  • โœ… Score panel below game board

๐Ÿ‘จโ€๐Ÿ’ป Development

Compilation Requirements

  • JDK 8+ (for lambda expressions)
  • Supports emoji rendering on Windows (Segoe UI Emoji font)

File Structure

All .java files should be in the same directory for compilation.

๐Ÿ“„ License

This is a learning project. Feel free to use, modify, and distribute as needed.

๐Ÿค Contributing

Feel free to fork this project and add your own features! Some ideas:

  • Add sound effects
  • Create new food types
  • Implement power-ups
  • Add multiplayer support
  • Create custom themes

๐ŸŽฎ Enjoy Playing!

Have fun playing the Snake Game! Try to beat your high score and master all difficulty levels! ๐Ÿ๐Ÿ†


Made with โค๏ธ using Java Swing

Last Updated: November 15, 2025

About

A modern Java Swing-based Snake Game with multiple difficulty levels, special food types, high score tracking, wall collision toggle, pause/resume, and emoji support. Features smooth controls, glowing effects, countdown timers, and persistent storage for scores. Cross-platform with EXE and JAR builds.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors