Blog

Rust Guessing Game

First Rust Code
CLI Game
Guess a number
Technical

A game made in Rust language.

Rust Image

Author: Shrey

Publish Date: Wed Apr 19 2023

Guessing Game

Github Repo

Motivation

I have been reading the Rust Book a lot lately. I am intrigued as to how much better Rust is compared to all other languages. I want to keep going deeper and learn more about the language. I wanted to see how much I have learnt about the language by building a simple CLI based game using the language. I saw that they have an excercise in their docs regarding a guessing game so I read the document and started to code this. I went overboard and added lot more functionality than what the docs offered. I implemented a difficulity system, a score caculator, added time tracker and tries counting to it.

I enjoyed everything about the language, especially how easy it was to implement this considering the performance and bug free code I got from this.

Rules

  • Pick the Difficulity.
  • Try to guess the number that is generated secretly.
  • The faster and lesser tries you take, the higher score you get.

Difficulity

Difficulity increases the scope of the number you need to guess.

  1. Easy (1 - 100)
  2. Medium (1 - 250)
  3. Hard (1 - 500)

Score

Score = {time taken to complete in secs} * {count of guesses taken to complete}

Compile & Run

git clone https://github.com/shreyydev/rust-guessing_game.git

cd guessing_game

cargo run