Skip to content

Battleship game implemented in Rust

License

Notifications You must be signed in to change notification settings

orhun/battleship-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battleship 🚢

Battleship game implemented in Rust.

demo

Fully playable between 2 players on the terminal.

To play on the public instance:

$ nc battleship.orhun.dev 1234

Building

Minimum supported Rust version: 1.38.0

$ cargo build --release

Running

$ ./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:

$ nc 127.0.0.1 1234

Docker

Dockerfile is available in the repository.

Building

$ docker build -t battleship .

Running

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

hit

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

grids

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
  1. Destroyer
▯
▯
  1. Battleship
▧▧
▧▧
▧▧

License

All code is licensed under The MIT License.