Author: Xander Brunet
This Python project implements a classic Hangman game with a focus on code organization through functions.
- Create a functional Hangman game.
word_list: A list of potential words for the game.word_by_letter: Stores the selected word as a list of individual letters.invisible_word: Represents the player's progress, initially filled with underscores.tried_letters: Keeps track of the player's previous guesses.tries: The number of remaining guesses (starts at 6).
- User-friendly interface with the game board updating after each turn.
- The main game function. Handles game setup, win/loss conditions, and the option to play again.
- Sub-functions:
prep_game()- Selects a random word.
- Initializes game variables (
word_by_letter,invisible_word,tried_letters,tries).
print_game()- Displays the game board (word progress, remaining tries, tried letters).
check_input(guess)- Validates the player's guess:
- Must be a single letter.
- Must not have been guessed previously.
- Validates the player's guess:
process_input(guess)- Updates
invisible_wordif the guess is correct. - Updates
tried_lettersand decrementstriesif the guess is wrong.
- Updates
- Welcome Screen
- Game Setup (
prep_game()is called) - Game Loop
- Player views the game board (
print_game()). - Player enters a guess.
- Input is validated (
check_input()). - Game state is updated (
process_input()). - Loop continues until the player wins or loses.
- Player views the game board (
- End of Game (Displays the outcome and the correct word)
- Play Again? (Prompts the user; calls
game()if yes)
Consider testing the game with the following inputs:
- Valid single letters.
- Invalid inputs (numbers, symbols, multiple characters).
- Winning scenarios.
- Losing scenarios.