A fun and interactive CLI numberβguessing game written in Go. A classic project to practice Go basics, randomization, input handling, and simple game designβall in your terminal.
- Overview
- Features
- Tech Stack & Requirements
- Installation & Build
- Usage Examples
- Code Structure
- Extendability Ideas
- Contributing
- License
This terminal-based game picks a random number and challenges you to guess it with feedback after each try. It demonstrates Go fundamentals like package structure, random number generation, input/output routines, and loop controlβperfect for beginners and educators.
- π² Random number generation between 1 and 100
- π Loop for continuous guessing until correct
- π Feedback hints: "too high" or "too low"
- π Counter for tracking attempts
- π Replay option after a win
- Go 1.18+ with module support
- Uses only Go standard libraries (
fmt
,bufio
,os
,math/rand
,time
)
Clone and build:
git clone https://github.com/MisaghMomeniB/Number-Guessing-Game-Go.git
cd Number-Guessing-Game-Go
go build -o guess-game main.go
Alternatively, run directly:
go run main.go
Run the game:
./guess-game
Sample session:
Welcome to Number Guessing Game!
I'm thinking of a number between 1 and 100.
Enter your guess:
> 50
Too high!
Attempts: 1
> 37
Too low!
Attempts: 2
...
> 42
π You guessed it in 7 attempts!
Play again? (y/n):
Number-Guessing-Game-Go/
βββ main.go # Game logic and I/O loop
- Generates a random target (
rand.Intn(100) + 1
) - Reads input using
bufio.Reader
and parses integers - Provides feedback and keeps guessing until correct
- Prompts to play again or exit
- π Add difficulty levels (e.g., easy: 1β10, hard: 1β1000)
- β±οΈ Add timer to track playtime
- ποΈ Maintain high-scores or best performance logs
- π¨ Add ASCII art or colorized output
- π¦ Package as a module with flags (e.g.,
--max=500
)
Contributions welcome! Suggestions include:
- Fork the repo
- Create a
feature/...
branch - Write clean, commented code
- Submit a Pull Request with changes
Released under the MIT License β see LICENSE
file for details.