Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

RubybeginnercliAI generated

Text-based Number Guessing Game with Difficulty Levels

Build a number guessing game for the terminal in Ruby: the computer picks a secret number, you guess, and it tells you whether to go higher or lower until you find it or run out of attempts. You choose a difficulty that changes the range (1 to 10, 1 to 100 or 1 to 1,000) and the number of guesses allowed, and the game keeps your best scores for each difficulty during the session. It's a perfect first Ruby program: you'll learn getting input with gets, converting and checking it, random numbers with rand, loops and conditions, hashes for storing scores, and splitting code into methods you can test.

Estimate
~5h
Steps
5
Completed by
0
Proposed by
codeseed.app

Standard Library

Project roadmap

  1. 01

    Build the guessing loop

    ~1h

    Write guess.rb: pick a secret number with rand(1..100), then loop asking for a guess with gets.chomp, convert it with Integer() inside a begin and rescue so letters don't crash the game, and say too high, too low or correct. Count the guesses and stop after a maximum number, revealing the number. Done when: a full game can be won or lost.

  2. 02

    Add difficulty levels

    ~1h

    Store the levels in a hash (easy: 1 to 10 with 5 guesses; medium: 1 to 100 with 7; hard: 1 to 1,000 with 10) and ask the player to choose one at the start, accepting a number or the name. Reject guesses outside the range with a message, without counting them. Done when: each level uses its range and number of guesses.

  3. 03

    Improve the hints

    ~1h

    Besides higher or lower, show the remaining guesses and the current possible range (for example between 43 and 67), and a warmer or colder hint compared with the previous guess. Warn when the player repeats a guess, without counting it. Done when: hints help narrow down the number clearly.

  4. 04

    Track statistics

    ~1h

    Let the player play several rounds, and keep in a hash per difficulty the games played, games won and the best score (fewest guesses). Print the statistics when the player quits. Done when: the statistics are correct after several rounds.

  5. 05

    Test the game logic

    ~1h

    Move the logic into methods that don't read input (checking a guess, updating the range and statistics), and write Minitest tests for them, using a fixed secret number. Done when: the tests pass.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~5h · 5 steps

Tech stack

Standard Library