HangWizard is a command-line Hangman game inspired by the Wizarding World of Harry Potter. This project was developed as the Final Project for CS50's Introduction to Programming with Python (CS50P).
The game challenges players to guess names of wizards, witches, and magical creatures using a dataset fetched from a public API and processed for offline gameplay.
main.py: The main entry point for the game logic, user input handling, and rendering.characters.py: A utility script used to fetch, clean, and cache data from the external API.HP_characters.txt: Local database file containing cleaned names. This allows the game to run offline without hitting the API repeatedly.requirements.txt: Project dependencies.
- Smart Data Caching: The project fetches data from the API once and stores it locally (
HP_characters.txt). This approach minimizes API usage and allows for offline gameplay. - Input Validation: Handles case-insensitive inputs and validates non-numeric guesses.
- Dynamic Masking: Automatically reveals special characters (spaces, hyphens) to improve user experience (e.g.,
_ _ _ _ _ _for "Harry Potter" becomes_ _ _ _ _ _ _ _ _ _ _). - Visual Progression: Displays ASCII art updates as the game progresses.
-
Clone the repository:
git clone https://github.com/nudchada/hangwizard.git cd hangwizard -
Install dependencies:
pip install -r requirements.txt
-
Run the Game:
python main.py
The file characters.py contains the logic to fetch data from the dedolist.com API.
- By default, the fetching code is commented out to preserve the existing curated list in
HP_characters.txtand avoid unnecessary network requests. - If you wish to update the dataset, uncomment the API request block in
characters.pyand run it once:python characters.py
Instead of fetching data from the API every time the game starts (which requires internet access and increases latency), I implemented a one-time data ingestion strategy:
characters.pyconnects to the API and parses the JSON response.- It extracts relevant names and writes them to a text file.
main.pysimply reads from this text file.
This design ensures the game is robust, fast, and offline-capable, mimicking how real-world applications cache static data.