Hangman
Video Demo: CS50P Final project demo
Description
Hangman is a command-line word-guessing game implemented in Python. Players attempt to guess a hidden word one letter at a time before running out of chances. The game supports multiple difficulty levels, game persistence (saving and loading games), and multiplayer challenge mode.
This project demonstrates concepts such as object-oriented design, input validation, persistence using pickle, modular architecture, and automated testing with pytest.
Features
- Three difficulty levels with different word lengths
- Multiplayer challenge mode
- Game saving and loading
- Automatic deletion of completed saved games
- Input validation and error handling
- Automatic display of numbers, spaces, and punctuation in hidden words
- Automated unit tests using pytest
- CLI-based interactive gameplay
Installation
To install the game with uv:
uv tool install hangman-p
This installs the game in an isolated environment and makes the hangman-p
command available globally.
You can also try the game without permanently installing it:
uvx --from hangman-p hangman-p
To install it into your active Python environment with pip:
python -m pip install hangman-p
Usage
Hangman is an interactive terminal game. After installation, start it with:
hangman-p
You can also run it as a Python module:
python -m hangman_p
Once started, the game is very intuitive and easy to follow.
###"Welcome to Hangman, the no-nonsense game Be smart, then you live. if not, you'll have to die by Hanging. You have a couple of options to pick from..... Press 'P' or 'play' if you think you are ready for the challenge, You may press 'I' or 'instructions' for a short explanation of how to play You may continue a previously saved game by pressing 'L' or 'load' Or you could just quit by pressing a 'Q' or typing 'quit'" "The word to guess is represented by a row of dashes These dashes represent each letter of the word. Words you cannot use include proper nouns such as names, places, and brands. If the guessing player suggests a letter which occurs in the word, the other player writes it in all its correct positions."
The guessing player must guess all of the letters of the word within a limited amount of chances. Failure to do so will result in his death by hanging.
Important note
In human mode, if the player is typing his word, it will not be displayed on the screen, it will be masked so as not to give the challenged player undue advantage.
Extras
You can actually reveal the word by pressing
:corcheat. This is a cheat for solving the problem and it is not recommended.
You can quit at any point by pressing
:qor typingquitwhereby you will be asked if you want to save the game or just quit. (The option to save is only available in the computer mode.)If you press
:hor typehistory, a list showing your guesses will be displayed.
Project structure
project.py # Main entry point
hangman_p/level.py # Difficulty configuration
hangman_p/game_engine.py # Core gameplay logic
hangman_p/dictionary.txt # list of possible words to be used (Computer mode)
hangman_p/game_persistence.py # Save/load game handling
pyproject.toml # package metadata and dependencies
test_project.py # pytest file
Design Decisions
- Object-oriented structure: I wasn't sure whether to use OOP or procedural paradigm. After thinking about what I will like to achieve, I decided that OOP was more convenient as it will handle game states more easily.
- Pickle-based persistence: I had the option of shelve or json as well, but I decided to vote for pickle mainly because of its elegant serialization and deserialization of python objects
- Shared input validation: Interactive input is validated with the reusable
cli-input-validatorpackage. - Pytest fixtures: were used for automated testing of interactive functions by monkeypatching input/output.
Contributing
Contributions are welcome. You do not need to build or publish distribution files to contribute.
- Fork the repository on GitHub and clone your fork.
- Create a branch for your change:
git switch -c feature/your-change
- Install the project dependencies and run the game locally:
uv sync
uv run hangman-p
- Run the tests before submitting your change:
uv run --with pytest pytest
- Commit your changes, push your branch, and open a pull request against the
mainbranch of this repository.
Author
Mayowa Pitan
Enjoy your Hangman experience and try not to be hanged...
good luck...
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hangman_p-0.1.4.tar.gz.
File metadata
- Download URL: hangman_p-0.1.4.tar.gz
- Upload date:
- Size: 139.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45df71493384c10082b5b21ac33e3a5e6f1ff94a2a0fcc17341a6238321f26cd
|
|
| MD5 |
d0510c629e0524a6b69885800e6764d2
|
|
| BLAKE2b-256 |
b846fdd26975d6b7cbbdee4bb0bb6e163af4e572112f8ba684590fe82af2edc5
|
Provenance
The following attestation bundles were made for hangman_p-0.1.4.tar.gz:
Publisher:
release.yml on VanPaitin/hangman-p
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hangman_p-0.1.4.tar.gz -
Subject digest:
45df71493384c10082b5b21ac33e3a5e6f1ff94a2a0fcc17341a6238321f26cd - Sigstore transparency entry: 2633836354
- Sigstore integration time:
-
Permalink:
VanPaitin/hangman-p@d21e8d65caca6f873cc0396b810a479d1f2dd364 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/VanPaitin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d21e8d65caca6f873cc0396b810a479d1f2dd364 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hangman_p-0.1.4-py3-none-any.whl.
File metadata
- Download URL: hangman_p-0.1.4-py3-none-any.whl
- Upload date:
- Size: 138.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b708733615c3355b91f4c204190fa4155cab41e3599f2299b0dfdf750afd9a3
|
|
| MD5 |
29f7a0a2c0947c4f1426c4c5f4f5156f
|
|
| BLAKE2b-256 |
d42ed7afa56126e9dde093f968696b606bb27502651c949b7c05fcbe9dd5025b
|
Provenance
The following attestation bundles were made for hangman_p-0.1.4-py3-none-any.whl:
Publisher:
release.yml on VanPaitin/hangman-p
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hangman_p-0.1.4-py3-none-any.whl -
Subject digest:
7b708733615c3355b91f4c204190fa4155cab41e3599f2299b0dfdf750afd9a3 - Sigstore transparency entry: 2633836406
- Sigstore integration time:
-
Permalink:
VanPaitin/hangman-p@d21e8d65caca6f873cc0396b810a479d1f2dd364 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/VanPaitin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d21e8d65caca6f873cc0396b810a479d1f2dd364 -
Trigger Event:
push
-
Statement type: