Skip to content

redshift-quasar/Hangman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍌 Hangman – Fruit Edition (C++)

A fun command-line version of the classic Hangman game, written in C++ using standard libraries and random fruit names!


πŸ•ΉοΈ Gameplay

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

🧰 Requirements

To compile and run this C++ project, make sure your system meets the following:

βœ… Required

  • C++11 or higher
    • The code uses modern features like <random> and range-based for loops.
  • C++ Compiler
    • Recommended: g++ (GNU Compiler)
    • Alternatives: clang++, MSVC (Windows)
  • Terminal or Command Prompt
    • To compile and execute the program via command line.

πŸ–₯️ Platform Support

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

πŸ§ͺ Tested On

  • Ubuntu 22.04 – g++ 11
  • Windows 10 – MinGW via Git Bash

πŸš€ How to Run

  1. Clone the repository or download the file:

    git clone https://github.com/redshift-quasar/Hangman.git
    cd Hangman
  2. Compile the program:

    g++ hangman.cpp -o hangman
  3. Run the game:

    ./hangman

✨ Features

  • βœ… Random Word Generation Uses C++11’s <random> library with std::random_device and mt19937 for 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 with system("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.


πŸ“„ License

This game is licensed under the MIT License.

Available for free use, modification, and distribution.


πŸ€” Notes

  • Clear screen uses system("clear") β†’ works on Linux/macOS. On Windows, replace with:

    system("cls");
  • To add more words, expand the fruits[] array.


πŸ™‹β€β™‚οΈ Author

Atharva Patel

GitHub: redshift-quasar
Happy hacking!

About

Hangman Game using C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages