This content originally appeared on DEV Community and was authored by Bek Brace
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:
- Random Ship Placement: Ships are placed randomly ensuring no overlaps or out-of-bounds positioning.
- User Input: You can fire at coordinates through basic user input.
- Game Board Display: The game board displays hits, misses, and ships using different symbols.
- Simple Game Loop: The game runs in a turn-based loop.
- 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
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.
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 🚀
This content originally appeared on DEV Community and was authored by Bek Brace
Bek Brace | Sciencx (2024-06-23T20:03:38+00:00) Battleship Game in RUST. Retrieved from https://www.scien.cx/2024/06/23/battleship-game-in-rust/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.