This is a simple command-line "Guess the Number" game implemented in Rust. The goal of the game is to guess a randomly generated number between 1 and 100. The program provides feedback on whether the guess is too high or too low, and tracks the number of guesses made. This isn't meant to be the most efficient code, I am using this as a fun way to learn the features of Rust. There are a lot of comments for the code mainly to help me remember what im doing.
-
Install Rust:
- Go to the official Rust website: https://www.rust-lang.org/learn/get-started
- Download and run the installer for Windows (
rustup-init.exe
). - Follow the on-screen instructions to install Rust.
-
Verify Installation:
- Open a terminal (Command Prompt or PowerShell) and type the following command:
rustc --version
- This should output the installed version of Rust.
- Open a terminal (Command Prompt or PowerShell) and type the following command:
-
Install the Game:
- Clone the repository to your local machine using
git
:git clone https://github.com/JonWatkins/guess-the-number.git
- Navigate to the project directory:
cd guess-the-number
- Clone the repository to your local machine using
-
Install Rust:
- Open the Terminal and install Rust using the
rustup
installer:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Follow the on-screen instructions to install Rust.
- Open the Terminal and install Rust using the
-
Verify Installation:
- After installation is complete, check the installed version of Rust by running:
rustc --version
- After installation is complete, check the installed version of Rust by running:
-
Install the Game:
- Clone the repository:
git clone https://github.com/JonWatkins/guess-the-number.git
- Navigate to the project directory:
cd guess-the-number
- Clone the repository:
-
Install Rust:
- Open a terminal and run the following command to install Rust via
rustup
:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Follow the on-screen instructions to install Rust.
- Open a terminal and run the following command to install Rust via
-
Verify Installation:
- Check the Rust version after installation by running:
rustc --version
- Check the Rust version after installation by running:
-
Install the Game:
- Clone the repository:
git clone https://github.com/JonWatkins/guess-the-number.git
- Navigate to the project directory:
cd guess-the-number
- Clone the repository:
Once you have installed Rust and cloned the repository, you can build the project.
-
Navigate to the Project Directory: Ensure you're in the directory where the game code is located:
cd guess-the-number
-
Build the Project: To compile the project, run the following command:
cargo build --release
This will compile the project in release mode. The executable will be placed in the target/release directory.
After building the project, you can run the "Guess the Number" game on your system.
-
Navigate to the Project Directory: Make sure you are in the project folder (where the Cargo.toml file is located):
cd guess-the-number
-
Build the Project: First, you need to build the project in release mode:
cargo build --release
This will compile the project and optimize it for performance. The compiled executable will be located in the target/release directory.
-
Run the Game: After building the project, run the game with the following command:
- On Linux/macOS:
./target/release/guessing_game
- On Windows:
.\target\release\guessing_game.exe
- On Linux/macOS:
-
Game Flow:
- The game will prompt you to input a guess.
- You have to guess a secret number between 1 and 100.
- After each guess, the game will tell you if your guess is too high, too low, or correct.
- The game will continue until you guess the correct number.
- The number of guesses will be tracked, and once you win, the total number of guesses will be displayed.
-
Example Output:
Guess the number Please input your guess: 50 Too small Please input your guess: 75 Too big Please input your guess: 62 Too small Please input your guess: 68 You win, in 4 guesses!
This project is licensed under the MIT License - see the LICENSE file for details.