Skip to content

zacniewski/Hangman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hangman Game

A classic command-line Hangman game written in Python.

Table of Contents


Introduction

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.

Features

  • 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.

How to Play

  1. The game starts by choosing a random animal name.
  2. You are shown underscores _ representing each letter of the word.
  3. You have 5 attempts to guess the word correctly.
  4. For every incorrect guess, the number of turns decreases.
  5. You win if you guess all the letters before running out of turns.
  6. You lose if you run out of turns before guessing the word.

Installation and Running

Prerequisites

  • Python 3.x installed.

Setup

  1. Clone this repository or download the files.
  2. Ensure hangman.py and animals.txt are in the same directory.

Running the Game

python hangman.py

Game Logic Flow

Below 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]
Loading

Code Structure

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).

Future Enhancements

  • 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.

About

Simple hangman game with animals' names

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages