This Python program implements a text-based version of the classic Hangman game. In Hangman, players guess letters to uncover a hidden word, and they have limited attempts to guess the correct word.
This Hangman game is written in Python and uses the OpenAI GPT-3.5 Turbo model for generating random words and assisting players during the game. It offers a simple command-line interface for playing.
- You start with 0 points.
- You can choose whether or not to set the language of the word.
- The game selects a random word for you to guess.
- You can guess letters or the entire word.
- For each incorrect guess, you lose a point.
- The game continues until you guess the word correctly or accumulate 11 incorrect guesses.
- If you guess the word correctly, you win.
- If you reach 11 incorrect guesses, the game ends, and you lose.
To run the Hangman game, follow these steps:
-
Clone the repository:
git clone https://github.com/H1B0B0/hangman-game.git
-
Navigate to the project directory:
cd hangman-game
-
Install the required Python packages:
pip install openai click
-
Set up your OpenAI API key as an environment variable:
- Linux:
export OPENAI=your-api-key
- Windows:
setx OPENAI "Variable value"
- Linux:
-
Run the game:
- Linux:
python3 hangman.py
- Windows:
py -3 hangman.py
- Linux:
Once the game is running, follow the prompts to play. Here's a brief overview of how to play:
-
Start the game by typing "yes" when prompted.
-
Optionally, choose to set the language of the word by entering "yes" or "no."
-
If you chose to set the language, enter the desired language.
-
The game selects a random word, and you'll see underscores representing the letters of the word.
-
Start guessing by entering letters or the entire word.
-
For each incorrect guess, you lose a point, and part of the hangman figure is drawn.
-
Continue guessing until you guess the word correctly or accumulate 11 incorrect guesses.
-
If you guess the word correctly, you win the game.
-
If you reach 11 incorrect guesses, the game ends, and you lose.
You can configure the game by setting your OpenAI API key as an environment variable and customizing the GPT-3.5 Turbo model. You can also modify the game's behavior by editing the hangman.py
file.
This Hangman game is open-source software released under the MIT License. You can find the full license details in the LICENSE file.
Enjoy playing Hangman! If you have any questions or encounter issues, please feel free to open an issue in the GitHub repository.