Skip to content

milesapnash/JavaSnake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaSnake

A small Snake game for the desktop, built with Java Swing.

Requirements

  • JDK 21 (or newer compatible release)
  • Apache Maven 3.9+ (for the recommended build)

Check your environment:

java -version
javac -version
mvn -version

Build and run

From the repository root:

mvn

This runs the project’s default goal: compile, then start the game.
Equivalent explicit command:

mvn compile exec:java

Note: 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 test

Run tests with Checkstyle and SpotBugs checks:

mvn verify

Without Maven

If 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.Game

Windows (PowerShell):

javac -d out -encoding UTF-8 (Get-ChildItem -Recurse -Path src\main\java\*.java).FullName
java -cp out com.mapna.snake.Game

The 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.

Controls

Action Keys
Move W A S D or arrow keys
Pause / resume P
Restart (after game over or win) R
Quit Esc

Screenshots

Gameplay

(WASD or arrow keys to move.)

Gameplay screenshot

Pause menu

(P to pause or resume.)

Pause menu screenshot

Game over

(R to restart, Esc to close.)

Game over screenshot

Gameplay

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.

High score

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).

License

See LICENSE.

About

A Snake game for the desktop, built with Java Swing.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages