https://github.com/orhun/battleship-rs
Battleship game implemented in Rust
https://github.com/orhun/battleship-rs
battleship battleship-game battleship-multiplayer hacktoberfest rust-game rust-gamedev tcp-sockets
Last synced: 4 months ago
JSON representation
Battleship game implemented in Rust
- Host: GitHub
- URL: https://github.com/orhun/battleship-rs
- Owner: orhun
- License: mit
- Created: 2022-04-26T17:45:47.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-29T20:50:06.000Z (over 1 year ago)
- Last Synced: 2025-04-15T21:42:50.484Z (7 months ago)
- Topics: battleship, battleship-game, battleship-multiplayer, hacktoberfest, rust-game, rust-gamedev, tcp-sockets
- Language: Rust
- Homepage:
- Size: 334 KB
- Stars: 92
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
## Battleship 🚢
[Battleship game](https://en.wikipedia.org/wiki/Battleship_(game)) implemented in Rust.

Fully playable between 2 players on the terminal.
To play on the public instance:
```shell-session
$ nc battleship.orhun.dev 1234
```
### Building
Minimum supported Rust version: `1.38.0`
```shell-session
$ cargo build --release
```
### Running
```shell-session
$ ./target/release/battleship
```
This will start the server on port `1234`, then players can connect to it with any tool that supports TCP sockets. For example, using [netcat](https://en.wikipedia.org/wiki/Netcat):
```shell-session
$ nc 127.0.0.1 1234
```
### Docker
[Dockerfile](./Dockerfile) is available in the repository.
#### Building
```shell-session
$ docker build -t battleship .
```
#### Running
```shell-session
$ docker run --rm -d --name battleship -p 1234:1234 battleship
```
### Configuring
You can use the following environment variables for specifying the game settings:
- `BATTLESHIP_SOCKET`: TCP socket address (default: `127.0.0.1:1234`)
- `BATTLESHIP_GRID_WIDTH`: Width of the game grid (default: `10`)
- `BATTLESHIP_GRID_HEIGHT`: Height of the game grid (default: `10`)
### Playing
After joining the game, players take turns firing shots (by calling out a grid coordinate) to attempt to hit the opponent's enemy ships. Example coordinates would be `a1`, `g8`, `E4`, `I2`, and so on.

Each player has two grids: an upper and lower grid.

The lower grid views the location of the player's own ships, while the upper grid shows the shots fired toward the opponent and also gives information about whether those shots were hits or misses.
- `☒`: hit
- `✕`: missed
#### Ship types
1. Boat
```
â–³
```
2. Destroyer
```
â–¯
â–¯
```
3. Battleship
```
â–§â–§
â–§â–§
â–§â–§
```
### License
All code is licensed under The MIT License.