A classic Snake Game built using Java Swing and AWT, featuring keyboard controls, real-time game updates, collision detection, scoring, restart functionality, and sound effects.
The game is also packaged as a Java JAR and deployed to the web using CheerpJ, allowing the Java application to run directly in a modern web browser.
No Java installation is required to play the browser version.
- Classic Snake gameplay
- Smooth snake movement
- Food spawning system
- Score tracking
- Snake growth
- Wall and self-collision detection
- Game Over screen
- Restart functionality
- Apple-eating sound effect
- Browser-based version using CheerpJ
- Automatic deployment using GitHub Actions
- Java 17
- Java Swing
- Java AWT
- CheerpJ
- GitHub Pages
- GitHub Actions
- Java JDK 17+
- Any Java IDE or terminal
git clone https://github.com/s4chinjha/Snake_Game.git
cd Snake_GameCompile the source files:
mkdir -p build/classes
javac -d build/classes src/*.javaRun the game:
java -cp build/classes SnakeGame| Key | Action |
|---|---|
| ↑ | Move Up |
| ↓ | Move Down |
| ← | Move Left |
| → | Move Right |
| R | Restart after Game Over |
Snake_Game/
├── src/
│ ├── SnakeGame.java
│ ├── GameFrame.java
│ └── GamePanel.java
├── res/
│ └── sounds/
│ └── appleEaten.wav
├── web/
│ ├── index.html
│ └── SnakeGame.jar
└── .github/
└── workflows/
└── deploy.yml
The web version is automatically deployed to GitHub Pages using GitHub Actions.
Java Swing Game
↓
Java 17
↓
JAR File
↓
CheerpJ
↓
Browser
↓
GitHub Pages
- Java Swing and AWT application development
- Game loops and rendering
- Keyboard event handling
- Collision detection
- Java resource management
- JAR packaging
- Running Java applications in the browser using CheerpJ
- GitHub Actions and GitHub Pages deployment
- Fullscreen browser mode
- Difficulty levels
- Pause/resume functionality
- High-score persistence
- Improved graphics and animations
Made with ❤️ by Sachin Kumar Jha