Skip to main content

A command-line Hangman game.

Project description

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
  • Automated unit tests using pytest
  • CLI-based interactive gameplay

Usage

This game is a REPL game, i.e it is being played from and with the Terminal.

To run it locally from this repository:

python project.py

After installing it as a package, run:

hangman-p

You can also run it as a Python module:

python -m hangman_p

To build distribution files for publishing:

uv build

This creates a wheel and source distribution in dist/. To upload them to PyPI after configuring a PyPI API token:

uv publish

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 :c or cheat. This is a cheat for solving the problem and it is not recommended.

You can quit at any point by pressing :q or typing quit whereby 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 :h or type history, 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/utilities.py    # Helper input validation utilities
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
  • Modular utilities: This decision was made after I found that I was validating inputs in several places of the program. I decided to extract the logic to utilities.py to make input validation reusable and testable.
  • Pytest fixtures: were used for automated testing of interactive functions by monkeypatching input/output.

Author

Mayowa Pitan

Enjoy your Hangman experience and try not to be hanged...

good luck...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hangman_p-0.1.1.tar.gz (139.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hangman_p-0.1.1-py3-none-any.whl (138.5 kB view details)

Uploaded Python 3

File details

Details for the file hangman_p-0.1.1.tar.gz.

File metadata

  • Download URL: hangman_p-0.1.1.tar.gz
  • Upload date:
  • Size: 139.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hangman_p-0.1.1.tar.gz
Algorithm Hash digest
SHA256 481bdc81402532f10ededac62a997209ecd4d9c64d6af9140fef11d67424543b
MD5 e6ed1effae6a20760e5d32ccf2c1f508
BLAKE2b-256 2a76fcbea0be01573db0b584a2c57016befc8bb4bc47a07374c9e38bfce1cd94

See more details on using hashes here.

File details

Details for the file hangman_p-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hangman_p-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 138.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for hangman_p-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89dca780944d889479497f6a1d493bd166e472200bed1bad18197ddf7bb9f3f4
MD5 5dc1a487276f01536501d77f3a2595b6
BLAKE2b-256 31c650381a1d1b26daf66b8f76e837b4faae1f9be2098806ca741c173ce3c242

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page