https://github.com/unvercan/snake
π A simple console-based Snake Game written in Java, supporting Maven and Docker. Play in the terminal with adjustable board size!
https://github.com/unvercan/snake
cli-game console-game docker game-development java java17 maven opensource snake-game terminal-game
Last synced: over 1 year ago
JSON representation
π A simple console-based Snake Game written in Java, supporting Maven and Docker. Play in the terminal with adjustable board size!
- Host: GitHub
- URL: https://github.com/unvercan/snake
- Owner: unvercan
- Created: 2025-03-01T07:14:53.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2025-03-08T07:20:50.000Z (over 1 year ago)
- Last Synced: 2025-03-08T08:25:21.197Z (over 1 year ago)
- Topics: cli-game, console-game, docker, game-development, java, java17, maven, opensource, snake-game, terminal-game
- Language: Java
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Snake Game
## Description
This is a simple console-based Snake game written in Java. The player controls a snake, moving it around the board to consume food and grow in length. The objective is to achieve the maximum snake length without colliding with the walls or itself.
## Features
- Classic Snake game mechanics
- Player-controlled movement using `W`, `A`, `S`, `D` keys
- Food generation at random locations
- Collision detection (walls and self)
- Win condition when the snake reaches the maximum possible length
- Console-based interface with real-time updates
- Adjustable board size
## Technologies Used
- **Java** (17 or later)
- **Maven** (if building the project manually)
- **Docker** (if running inside a container)
## How to Play
1. Run the application.
2. Control the snake using the following keys:
- `W` β Move up
- `A` β Move left
- `S` β Move down
- `D` β Move right
3. Eat food (`*`) to grow longer.
4. Avoid crashing into walls (`#`) or yourself.
5. The game ends when:
- The snake collides with a wall or itself (lose condition).
- The snake reaches the maximum possible length (win condition).
## Installation and Setup
### Prerequisites
- **Java 17** or later
- **Maven** (if building the project manually)
- **Docker** (if running inside a container)
### Running the Game (Java and Maven)
1. Clone the repository:
```sh
git clone https://github.com/unvercan/snake.git
cd snake
```
2. Build the project using Maven:
```sh
mvn clean package
```
- This command will clean any previous builds and package the project into a JAR file.
3. Run the game using the JAR file:
```sh
java -jar target/snake-1.0.jar boardWidth=15 boardHeight=8
```
- `boardWidth`: Defines the board width.
- `boardHeight`: Defines the board height.
### Running the Game (Docker)
1. **Build the Docker Image:**
```sh
docker build -t snake .
```
2. **Run the Docker Container:**
```sh
docker run --rm -it -e BOARD_WIDTH=15 -e BOARD_HEIGHT=8 snake
```
- `-t` adds the name of the image while building the Docker file.
- `--rm` ensures the container is removed after it stops.
- `-it` keeps the container interactive for user input.
- `-e BOARD_WIDTH=15`: Sets the board width inside the container.
- `-e BOARD_HEIGHT=8`: Sets the board height inside the container.
Now you can play the Snake game directly in the terminal inside the Docker container!
## Project Structure
```
βββ src
β βββ tr.unvercanunlu.snake # Main package
β βββ App.java # Main Application entry point
β βββ Game.java # Game logic
β βββ util # Package for Utility classes
β βββ ConsoleUtil.java # Console related Utility class
β βββ InputUtil.java # Input related Utility class
β βββ NumberUtil.java # Number related Utility class
β βββ constant # Package for Enums
β βββ Tile.java # Enum for board tiles
β βββ Status.java # Enum for game statuses
β βββ Move.java # Enum for movement directions
β βββ Input.java # Enum for player inputs
β βββ Action.java # Enum for possible actions
βββ pom.xml # Maven configuration file
βββ Dockerfile # Docker setup
```
## License
This project is open-source and available under the **MIT License**.
## Author
Γnver Can ΓnlΓΌ