🎯 Overview
Hangman Game is a modern take on the classic word guessing game, implemented in Python using Pygame for graphics and Pygbag for web deployment. The player must guess a hidden word by suggesting letters, with a limited number of incorrect guesses before the game ends.
This project demonstrates:
- Python fundamentals: control flow, data structures, and string manipulation
- Pygame: graphical interface, event handling, and game loop
- Pygbag: packaging and running Python games in the browser
🚀 Features & Mechanics
Random Word Selection
Each round uses a randomly chosen word from a customizable list.
Guess Tracking
Tracks correct and incorrect guesses, displaying missed letters.
Graphical Hangman
Shows hangman stages with Pygame graphics, updating with each error.
Virtual Keyboard
Supports mouse/touch input for mobile and desktop play.
Stats & Replay
Displays victories/defeats and allows instant restart after each round.
Input Validation
Handles invalid, repeated, or non-letter guesses gracefully.
Game Flow
- Start the game and a word is selected at random.
- Guess letters using keyboard or on-screen buttons.
- Each incorrect guess adds a part to the hangman drawing.
- Win by guessing all letters before reaching the max errors.
- Lose if the hangman is completed before the word is guessed.
- Restart easily after each round.
🛠️ Technologies & Deployment
- Python 3.x: Main programming language
- Pygame: Graphics, event handling, and game loop
- Pygbag: Converts Python/Pygame games to run in the browser (WebAssembly)
- HTML5/CSS3: Used for web packaging and styling
Pygbag Web Deployment
- Rename your main file to
main.py (required by Pygbag)
- Install pygbag:
pip install pygbag
- Build for web:
python -m pygbag --build .
- Open
build/web/index.html in your browser
- Ready for publishing on any static web host
# Example build command
python -m pygbag --build .
🎮 How to Play
Start Game
Run main.py locally or open index.html (web build) in your browser.
Guess Letters
Use your keyboard or click/tap the on-screen virtual keyboard to guess letters.
Track Progress
Correct guesses reveal letters; incorrect guesses add to the hangman drawing and error count.
Win or Lose
Win by guessing all letters before the hangman is completed. Lose if you reach the max errors.
Restart
Press any key or click the restart button to play again after a round ends.
Controls
- Keyboard: Type letters to guess, press any key to restart
- Mouse/Touch: Click/tap letters or restart button
🌟 Highlights & Customization
- Zero dependencies for web: Runs in browser with Pygbag, no installation needed
- Responsive design: Playable on desktop and mobile
- Customizable word list: Edit
WORD_LIST in main.py to add/remove words
- Easy to style: Colors and fonts match your portfolio palette
- Educational: Great for learning Python, Pygame, and web deployment
- Clean code structure: Well-organized and commented for easy extension
🚦 Project Status
✅ Completed
✅ Tested
✅ Responsive
✅ Web-ready
✅ Educational
All features implemented and tested. Play locally or in your browser. Clean, secure, and optimized code for learning and fun!