A small, classic Snake game implemented in Java + Swing. This repo contains a lightweight playable version used for learning and experimentation.
What's new
- Press SPACE when the game is over to restart the game (reset snake, place new food, reset direction).
- A running high score is tracked and displayed under the current score.
src/- Java source files (App.java,SnakeGame.java)bin/- compiled class files (output byjavac)lib/- external libraries (if any)
- Arrow keys: move the snake
- SPACE: when
Game Overis shown, press SPACE to restart
From the project root (where src and bin live) use these commands in PowerShell:
# compile
javac -d bin src\*.java
# run
java -cp bin AppIf you run the game with additional JVM flags (preview features, etc.), add them to the java command as you normally do.
- The main game logic is in
src/SnakeGame.java. The panel listens for key events and uses aTimeras the game loop. highScoreis kept in memory for the current application session only. If you'd like persistent high scores across runs, consider saving to a small file (e.g.,highscore.txt).
This project is small demo code — feel free to modify and use it for learning. No license file is included; add one if you intend to redistribute.