Overview
Hangman (Ahorcado) is a classic word-guessing game where you must identify a hidden word by guessing one letter at a time. You have 6 attempts to guess the word correctly before the hangman drawing is completed.The game features ASCII art that progressively builds the hangman figure with each wrong guess, creating visual tension!
How to Play
Game Rules
- Objective: Guess the hidden word by selecting letters from the alphabet
- Attempts: You start with 6 attempts (lives)
- Correct Guess: The letter appears in its correct position(s) in the word
- Wrong Guess: You lose one attempt and the hangman drawing progresses
- Win: Reveal all letters before running out of attempts
- Lose: Use all 6 attempts without completing the word
Game Interface
The interface is split into two columns: Left Column:- ASCII art hangman drawing (updates with each wrong guess)
- Remaining attempts counter
- The hidden word displayed with underscores (_) for unguessed letters
- Interactive letter keyboard (A-Z including Ñ)
- Game result messages
Implementation Details
Word Loading
The game loads words from an external file:streamlit_game.py:5
- Reads words from
Hangman/DATA/DATA.txt - Converts all words to uppercase for consistency
- Provides fallback words if file is missing
- UTF-8 encoding supports Spanish characters (Ñ)
ASCII Art Hangman
The game displays different stages of the hangman based on remaining attempts:streamlit_game.py:13
- 6 attempts: Empty gallows
- 5 attempts: Head added (O)
- 4 attempts: Body added (|)
- 3 attempts: Left arm added (/|)
- 2 attempts: Right arm added (/|\)
- 1 attempt: Left leg added (/|\, |, /)
- 0 attempts: Complete figure (/|\, |, / \)
Why ASCII Art?
Why ASCII Art?
ASCII art provides:
- Universal compatibility: Works in any text-based interface
- No external assets: No need for image files
- Instant rendering: Fast display without loading times
- Classic feel: Authentic to the original pen-and-paper game
Game Initialization
streamlit_game.py:149
hangman_word: The randomly selected word to guesshangman_guessed: Set of letters already guessed (prevents duplicates)hangman_attempts: Remaining lives (starts at 6)hangman_game_over: Game completion flaghangman_result: Win/loss message
Word Display Logic
The game reveals letters as they’re guessed:streamlit_game.py:174
- Iterate through each character in the secret word
- If the character has been guessed, show it
- Otherwise, show an underscore
- If any underscores remain, the game isn’t won yet
- Display with spaces between letters for readability
Example Display
Example Display
Secret word: PYTHONNo guesses: _ _ _ _ _ _Guessed P, O: P _ _ _ O _Guessed P, O, N: P _ _ _ O NComplete: P Y T H O N
Interactive Keyboard
The game creates a dynamic letter grid:streamlit_game.py:202
- 7 columns: Creates a neat grid layout
- 27 letters: Spanish alphabet (A-Z + Ñ)
- Dynamic state: Used letters become disabled
- Modulo positioning:
i % 7wraps letters to new rows - Instant feedback: Wrong guesses reduce attempts immediately
The keyboard includes Ñ to support Spanish words like “NIÑO” or “ESPAÑOL”!
Win/Loss Detection
streamlit_game.py:186
won = True)
Loss condition: Attempts reach 0
Result display:
- Win: Green success message
- Loss: Red error message with revealed word
Tips & Strategy
Best Letters to Guess First
Best Letters to Guess First
In English:
- Vowels: E, A, O, I, U (appear in most words)
- Common consonants: T, N, S, R, H
- Vowels: A, E, O, I, U
- Common consonants: S, N, R, L, D
Pattern Recognition
Pattern Recognition
- Short words (3-4 letters): Guess vowels first
- Long words (7+ letters): Look for common endings (-TION, -MENTE)
- Double letters: If you find one, the same letter might appear again
- Word fragments: _ A _ A could be CASA, RATA, NADA, etc.
Attempt Management
Attempt Management
- Don’t guess randomly: Think about likely letters
- Use word knowledge: Consider common Spanish words
- Avoid rare letters early: Save Q, X, Z for when you have more context
- 6 attempts is more than it seems: Don’t panic on the first wrong guess
Code Architecture
Session State Variables
| Variable | Type | Purpose |
|---|---|---|
hangman_word | str | The secret word to guess |
hangman_guessed | set | Letters already guessed |
hangman_attempts | int | Remaining wrong guesses allowed |
hangman_game_over | bool | Whether game has ended |
hangman_result | str | Win/loss message |
UI Layout Structure
streamlit_game.py:167
[1, 1]) create a balanced layout with ASCII art on the left and game controls on the right.
Game Flow Diagram
Customization Ideas
Add Custom Word Lists
Add Custom Word Lists
Create themed word lists:
- Programming terms: PYTHON, JAVASCRIPT, ALGORITHM
- Countries: ESPAÑA, MEXICO, ARGENTINA
- Animals: ELEFANTE, JIRAFA, RINOCERONTE
DATA.txt, one word per line!Difficulty Levels
Difficulty Levels
Modify attempts based on word length: