A fun command-line version of the classic Hangman game, written in C++ using standard libraries and random fruit names!
- The game picks a random fruit name (e.g., "banana", "grapefruit", etc.).
- You guess one letter at a time.
- If the guess is correct, it's revealed in the word.
- You have 6 incorrect guesses before the game ends.
- ASCII art draws the hangman as you make mistakes.
To compile and run this C++ project, make sure your system meets the following:
- C++11 or higher
- The code uses modern features like
<random>and range-basedforloops.
- The code uses modern features like
- C++ Compiler
- Recommended:
g++(GNU Compiler) - Alternatives:
clang++, MSVC (Windows)
- Recommended:
- Terminal or Command Prompt
- To compile and execute the program via command line.
| OS | Supported | Notes |
|---|---|---|
| Linux | ✅ | Tested on Ubuntu 22.04 with g++ |
| macOS | ✅ | Should work with clang++ |
| Windows | ✅ | Replace system("clear") with system("cls") or remove it for compatibility |
- Ubuntu 22.04 –
g++ 11 - Windows 10 – MinGW via Git Bash
-
Clone the repository or download the file:
git clone https://github.com/redshift-quasar/Hangman.git cd Hangman -
Compile the program:
g++ hangman.cpp -o hangman
-
Run the game:
./hangman
-
✅ Random Word Generation Uses C++11’s
<random>library withstd::random_deviceandmt19937for high-quality random fruit selection. -
🎨 ASCII-Based Hangman Drawing Visualizes the classic hangman figure stage-by-stage using ASCII characters as the player makes incorrect guesses.
-
🔠 Letter-by-Letter Guessing Accepts single-character inputs and updates the current word display in real time.
-
🧠 String Matching Logic Checks each guessed letter against the target word and updates only matching positions.
-
📺 Screen Clearing Between Guesses Uses
system("clear")to refresh the terminal after each guess for a cleaner game interface.⚠️ (Replace withsystem("cls")on Windows or remove for cross-platform support) -
⌛ Limited Guesses (6 chances) Game ends with “Game Over” and shows the full word if the player runs out of attempts.
-
🧹 Clean Output Display Structured and readable console UI that separates input, current word progress, and hangman visuals clearly.
-
📜 Expandable Word List Easily add more fruits or change the word category by editing the
fruits[]array. -
🛑 Safe Exit Program gracefully ends when the player either wins or loses, without crashes or memory issues.
This game is licensed under the MIT License.
Available for free use, modification, and distribution.
-
Clear screen uses system("clear") → works on Linux/macOS. On Windows, replace with:
system("cls");
-
To add more words, expand the
fruits[]array.
GitHub: redshift-quasar
Happy hacking!