This is a simple and fun Snake game implemented in Java, using a grid-based design to handle the game logic and UI elements. Players can control the snake using the arrow keys to move it around the grid, eating food to grow in size and gain points.
- Single-player and two-player modes
- Classic snake movement and growth
- Food and SuperFood items for the snake to eat
- Adjustable game speed
- Pause and restart functionality
- Game over detection and score tracking
- High score tracking and display
- Compile and run the game.
- Choose between single-player or two-player mode.
- Control the snake(s) using the arrow keys (for player 1) and W, A, S, D keys (for player 2, if applicable).
- Eat food and SuperFood items to grow the snake(s) and increase the score. SuperFood items provide double points and have a limited lifespan.
- Avoid colliding with the grid boundaries and the snake's own body.
- Press Spacebar to pause or resume the game.
- When the game is over, press Enter to restart.
- Java Development Kit (JDK) installed
- Clone the repository or download the source files.
- Navigate to the project directory.
- Compile the Java source files:
javac no/uib/inf101/sem2/controller/Game.java
- Run the compiled Java program:
java no.uib.inf101.sem2.controller.Game <numPlayers>
Replace <numPlayers>
with either 1
for single-player mode or 2
for two-player mode.
You can adjust various settings in the Game
class, such as the number of rows and columns in the grid, cell size, and the number of food and SuperFood items. Please refer to the source code for the specific variables to change.
This project is open-source and available for personal and educational use. Please provide appropriate credit if you use any part of this project in your own work.
Enjoy the game!
Here is a video of the application: https://www.youtube.com/watch?v=hgqXngQuM3o
Kind regards, Jørgen