A small Snake game for the desktop, built with Java Swing.
- JDK 21 (or newer compatible release)
- Apache Maven 3.9+ (for the recommended build)
Check your environment:
java -version
javac -version
mvn -versionFrom the repository root:
mvnThis runs the project’s default goal: compile, then start the game.
Equivalent explicit command:
mvn compile exec:javaNote: mvn exec:java alone can fail with ClassNotFoundException if the project has not been compiled yet—always include compile first, or use mvn as above.
Run unit tests:
mvn testRun tests with Checkstyle and SpotBugs checks:
mvn verifyIf you only have the JDK, compile every .java file under src/main/java, then run Game:
macOS / Linux:
javac -d out -encoding UTF-8 src/main/java/com/mapna/snake/*.java
java -cp out com.mapna.snake.GameWindows (PowerShell):
javac -d out -encoding UTF-8 (Get-ChildItem -Recurse -Path src\main\java\*.java).FullName
java -cp out com.mapna.snake.GameThe window icon loads from the classpath when run via Maven; with plain javac/java, the app falls back to src/main/resources/images/icon.png on disk.
| Action | Keys |
|---|---|
| Move | W A S D or arrow keys |
| Pause / resume | P |
| Restart (after game over or win) | R |
| Quit | Esc |
(WASD or arrow keys to move.)
(P to pause or resume.)
(R to restart, Esc to close.)
The snake speeds up as it grows — after eating 10 pieces of food the tick rate begins to decrease, making the game progressively harder. Fill the entire board to win.
The best score is stored in highscore.txt in the process working directory (usually the folder you run the game from). That file is ignored by Git (see .gitignore).
See LICENSE.


