A classic command-line Hangman game written in Python.
- Introduction
- Features
- How to Play
- Installation and Running
- Game Logic Flow
- Code Structure
- Future Enhancements
Hangman is a word-guessing game. The computer picks a secret word from a list (animals in this case), and the player tries to guess it by suggesting letters within a limited number of turns.
- Themed Words: Guess from a list of over 70 animal names.
- Visual Feedback: Shows correctly guessed letters and remaining turns.
- Robust Logic: Handles multiple occurrences of the same letter.
- Simple Interface: Easy-to-use command-line interface.
- The game starts by choosing a random animal name.
- You are shown underscores
_representing each letter of the word. - You have 5 attempts to guess the word correctly.
- For every incorrect guess, the number of turns decreases.
- You win if you guess all the letters before running out of turns.
- You lose if you run out of turns before guessing the word.
- Python 3.x installed.
- Clone this repository or download the files.
- Ensure
hangman.pyandanimals.txtare in the same directory.
python hangman.pyBelow is a simplified Mermaid diagram of the game flow:
graph TD
A[Start Game] --> B[Load Words from animals.txt]
B --> C[Select Random Secret Word]
C --> D[Initialize Hidden Word with underscores]
D --> E{Turns > 0?}
E -- Yes --> F[Prompt User for Guess]
F --> G{Letter in Secret Word?}
G -- Yes --> H[Reveal Letter in Hidden Word]
G -- No --> I[Decrement Turns]
H --> J{Hidden Word == Secret Word?}
I --> E
J -- Yes --> K[Victory!]
J -- No --> E
E -- No --> L[Game Over - Hangman Died]
K --> M[End]
L --> M[End]
| File | Description |
|---|---|
hangman.py |
The main Python script containing the game logic. |
animals.txt |
A text file containing a list of animal names (one per line). |
- Add difficulty levels (easy, medium, hard).
- Implement a graphical user interface (GUI) using Tkinter or Pygame.
- Add categories (e.g., countries, movies, food).
- Visual ASCII art for the hangman stages.
- Track high scores.