Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

C++ Hangman Game

A console-based Hangman word-guessing game written in C++.

Screenshots

Menu & Rules Gameplay
Menu Gameplay

About

This project was developed as a Programming Fundamentals coursework assignment at NASTP Institute of Information and Technology (NIIT), a constituent of Air University. It demonstrates core C++ programming concepts through an interactive console game where the player guesses a hidden word letter by letter before running out of lives.

Features

  • Three difficulty levels — Easy, Medium, and Hard
  • Three word categories per level — Animals, Nature, Fruits, Cities, Countries, Space, Sports
  • ASCII art hangman — visual progression as lives are lost
  • Input validation — handles invalid menu selections and non-numeric input gracefully
  • Duplicate guess detection — warns when a letter has already been guessed
  • In-game rules — accessible from the difficulty selection menu (option 4)
  • Replay option — play multiple rounds without restarting the program

How the Game Works

  1. The player is welcomed and selects a difficulty level (Easy, Medium, or Hard).
  2. Within the chosen difficulty, the player picks a word category.
  3. A random word from that category is selected and displayed as underscores.
  4. The player guesses one letter at a time. Correct guesses reveal matching positions; incorrect guesses cost one life.
  5. The player starts with 5 lives. An ASCII hangman figure builds up with each wrong guess.
  6. The game ends when the word is fully revealed (win) or all lives are lost (lose).
  7. After each round, the player can choose to play again.

Technologies and Concepts Demonstrated

  • C++ Standard Library: <iostream>, <vector>, <algorithm>, <cstdlib>, <ctime>, <limits>
  • Windows console I/O: <conio.h> for getch()
  • Functions and forward declarations
  • std::vector and std::string
  • std::find for searching containers
  • switch statements and nested do…while loops
  • Input validation with cin.fail(), cin.clear(), and cin.ignore()
  • Pseudo-random number generation with srand() and rand()
  • Menu-driven console interface

Requirements

  • Operating system: Windows
  • Compiler: Any C++ compiler that provides <conio.h> — for example:
    • MinGW (g++ for Windows)
    • Microsoft Visual C++ (MSVC)

Note: This project uses <conio.h> and getch(), which are Windows-specific. It will not compile on Linux or macOS without modification.

Build and Run

Using g++ (MinGW):

g++ hangman.cpp -o hangman.exe
hangman.exe

Using MSVC (Developer Command Prompt):

cl hangman.cpp
hangman.exe

How to Play

  1. Run the program and press any key to start.
  2. Enter 4 at the difficulty menu to read the rules (optional).
  3. Select a difficulty level: 1 (Easy), 2 (Medium), or 3 (Hard).
  4. Select a word category: 1, 2, or 3.
  5. Guess letters one at a time — use lowercase letters.
  6. You have 5 lives per round.
  7. After the round ends, enter y to play again or n to quit.

Project Structure

cpp-hangman-game/
├── docs/
│   └── screenshots/    # Gameplay screenshots
├── hangman.cpp         # Complete game source code
├── .gitignore          # C++/Windows build artifact exclusions
└── README.md           # This file

Known Limitations

  • Windows only — depends on <conio.h> / getch() for the initial keypress prompt.
  • Lowercase input only — guesses must be entered in lowercase to match the word lists.
  • Single-character input — the game reads one character per guess; entering multiple characters may leave extra input in the buffer.
  • Hardcoded word lists — words are defined directly in the source code rather than loaded from an external file.
  • Fixed lives — all difficulty levels use the same number of lives (5).

Author

Muhammad Umer Iqbal Programming Fundamentals — NASTP Institute of Information and Technology (NIIT), Air University


This project was created as an academic exercise to demonstrate foundational C++ programming skills.

About

A console-based Hangman game written in C++ as a Programming Fundamentals academic project.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages