DEV Community

Cover image for Battleship Game in RUST
Bek Brace
Bek Brace

Posted on

Battleship Game in RUST

Hey! Amir here! 🌟

First of all: Thank you so much for the incredible interaction I had had when I shared my Rust Full Course for Beginners last month.
I'm glad to know that it was helpful to you, even if just a bit.
Every opportunity to provide value and help you learn is something I cherish deeply.
I'll always be ready to support your learning journey, guys.

Today, I’m super excited to share my latest project with you all: a classic Battleship game implemented in Rust.
This isn’t just a throwback to those childhood days of sinking ships on graph paper, but also a neat little journey through the awesomeness of Rust's standard library for I/O handling and random number generation.
So, let me show you what I have for you today, and maybe even contribute to this Battleship game.

Features

Let's kick things off by highlighting some cool features of our Battleship game:

  1. Random Ship Placement: Ships are placed randomly ensuring no overlaps or out-of-bounds positioning.
  2. User Input: You can fire at coordinates through basic user input.
  3. Game Board Display: The game board displays hits, misses, and ships using different symbols.
  4. Simple Game Loop: The game runs in a turn-based loop.
  5. Game Over Detection: It checks for game over conditions, so you know when you've won (or lost)! # Installation First things first, you need to have Rust installed. If you haven’t got it yet, head over to rust-lang.org and get it.

Once Rust is all set up, cloning the repository is your next step. Here’s how you do it:

git clone https://github.com/BekBrace/rust-bship-game.git
cd battleship-rust
cargo build
cargo run
Enter fullscreen mode Exit fullscreen mode

Here's the game tutorial if you prefer to watch it :-)

Game Rules

For those who need a quick refresher on how Battleship works, here are the basics:

  • Each player has a 10x10 board.
  • Ships of different sizes (5, 4, 3, 3, 2) are randomly placed on the board.
  • Players take turns firing at each other’s boards by entering coordinates.
  • Hits are marked with a red dot (●), and misses with a blue dot (Β·).
  • The game continues until all ships of one player are sunk.

Image description

And there you have it, folks! A full Battleship CLI game in Rust.
Whether you're a Rustacean or just someone looking to play a fun game, I hope this project brings you as much joy as it brought me creating it.

Stay safe, happy coding, and may the best captain win :-)
Catch you next time,
Amir πŸš€

Top comments (2)

Collapse
 
ajinkyax profile image
Ajinkya Borade

great voice and good video

Collapse
 
bekbrace profile image
Bek Brace

Cheers