How emmanueldrivescode/number-guessing-game works
Purpose and entry point
This is a Python command-line number-guessing game. A player selects a difficulty, guesses a random number from 1–100 within an attempt limit, receives hints, and can replay. Start the application with main.py.
Paths: main.py, game.py
Application orchestration
main.py is the CLI-facing coordinator: it should present the game loop, invoke a game round, and handle the play-again lifecycle. It forms the boundary between terminal input/output and domain logic.
Paths: main.py, game.py
Game-round engine
game.py owns core gameplay state and control flow: random target generation, difficulty-derived attempt budgets, guess evaluation, hint delivery, success/failure determination, and elapsed-time tracking. It should not need to know persistence details beyond calling score/stat interfaces.
Paths: game.py, main.py
Difficulty and hint behavior
Difficulty is a domain policy expressed through the round engine: Easy permits 10 attempts, Medium 5, and Hard 3. Guess feedback narrows the range (“greater”/“less”), while difficulty may govern hint behavior. Inputs must be validated before they affect round state.
Paths: game.py
High-score persistence
High scores are persisted locally as JSON. highscores.py is the persistence/service boundary for reading prior records, comparing a winning result—likely attempts and/or time—and writing improved scores. The application uses the repository working directory as its storage location.
Paths: highscores.py, highscores.json
Aggregate game statistics
stats.py maintains durable aggregate counters for games played, wins, losses, and derived win rate. Each completed round should report exactly one terminal result to this component; stats.json is the backing store.
Paths: stats.py, stats.json, game.py
Runtime and external boundaries
The system runs on Python 3 in a local terminal and relies on standard-library facilities: random-number generation, timing, and JSON serialization. There are no network services, database systems, web runtime, or third-party infrastructure indicated. Persistent JSON files are shared mutable state and require tolerant handling of missing, malformed, or empty files.
Paths: main.py, highscores.json, stats.json
Main entry points: game.py Round engine · highscores.py High-score service · stats.py Statistics service · main.py Application loop
Components 12
CLI Application
- Local terminal · Player input and game output.
- Application loop · Runs rounds and manages replay.
main.py
Game Domain
- Round engine · Owns round state, validation, hints, and terminal outcomes.
game.py - Difficulty policy · Sets Easy, Medium, and Hard attempt budgets.
game.py - Guess feedback · Evaluates guesses and provides greater/less hints.
game.py - Randomness and timing · Generates targets and measures elapsed time.
Local Persistence
- High-score service · Reads, compares, and writes improved winning scores.
highscores.py - Statistics service · Records one win or loss for every completed round.
stats.py - High scores · Local durable score records.
highscores.json - Game statistics · Local aggregate counters and win rate data.
stats.json - JSON serialization · Handles local JSON data with tolerant file loading.
Other components
- Python 3 runtime
Connections 15
- Local terminal → Application loop: input / output
- Application loop → Round engine: starts round
- Round engine → Difficulty policy: applies attempt budget
- Round engine → Guess feedback: evaluates validated guesses
- Round engine → Randomness and timing: uses
- Round engine → High-score service: reports winning result
- Round engine → Statistics service: reports terminal result
- High-score service → High scores: reads / writes
- Statistics service → Game statistics: reads / writes
- High-score service → JSON serialization: serializes
- Statistics service → JSON serialization: serializes
- Python 3 runtime → Application loop: executes
- Python 3 runtime → Round engine: executes
- Python 3 runtime → High-score service: executes
- Python 3 runtime → Statistics service: executes