A Python implementation of the classic Hangman game with a graphical user interface built using PyQt6 and Firebase Realtime Database for word storage.
This is the start screen where players can enter their name and select a difficulty level.
This is the in-game screen where players can guess letters and see their progress.
- User-friendly graphical interface
- Multiple difficulty levels (Easy, Medium, Hard)
- Custom word management (add and remove words)
- Persistent word storage using Firebase
- Visual hangman progression
- Keyboard and mouse input support
- Python 3.11 or higher
- Firebase account
- Internet connection for database access
-
Clone the repository:
git clone https://github.com/Armaan4477/Hangman.git cd Hangman -
Install the required dependencies:
pip install -r requirements.txt
- Go to the Firebase Console
- Click "Add project" and follow the setup wizard
- Give your project a name (e.g., "Hangman Game")
- Follow the prompts to complete the setup
- In the Firebase Console, select your project
- Click on "Realtime Database" in the left sidebar
- Click "Create Database"
- Start in test mode for development (You'll set up proper security rules later)
- Choose a database location closest to your users
- In the Realtime Database section, click the overflow menu (three dots) and select "Import JSON"
- Upload the provided
hangman_DB-export.jsonfile - This will populate your database with the required structure and some initial words
- In the Realtime Database section, click the "Rules" tab
- Replace the existing rules with the contents of the provided
rules.txtfile - Click "Publish"
- In the Firebase Console, go to Project Settings (gear icon)
- Click on the "Service Accounts" tab
- Click "Generate new private key"
- Save the downloaded JSON file as
credentials.jsonin your project directory - Open the
credentials.jsonfile and add thedatabaseURLfield manually:
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
"private_key": "-----BEGIN PRIVATE KEY-----\nYour Private Key\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-xxxxx@your-project-id.iam.gserviceaccount.com",
"client_id": "your-client-id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-xxxxx%40your-project-id.iam.gserviceaccount.com",
"universe_domain": "googleapis.com",
"databaseURL": "https://your-project-id-default-rtdb.firebaseio.com"
}Important: Replace
https://your-project-id-default-rtdb.firebaseio.comwith your actual Firebase Realtime Database URL, which you can find in the Realtime Database section of the Firebase Console.
- Run the
encrypt_credentials.pyscript to create an encrypted version of your credentials:python encrypt_credentials.py
- This will create a file named
encrypted_credentials.txtin the same directory ashangman.py. - Ensure that
encrypted_credentials.txtis in the same directory ashangman.pyfor the game to work. - The script will also verify that the encryption works by attempting to decrypt the credentials.
- If successful, you will see a message indicating that the credentials were successfully decrypted.
Execute the main Python script:
python hangman.py- Enter your name and select a difficulty level in the start screen
- Click "Start Game" to begin
- Guess letters by either:
- Clicking on the letter buttons
- Typing on your keyboard
- You have 7 lives (incorrect guesses) before the game ends
- Try to guess the word before running out of lives!
- Type a letter to guess it
Ctrl+Gto give up the current gameCtrl+Rto restart with a new word
- Click "Add word" to add your own words to the database
- Click "Remove Current word" to remove the current word from the database
- Words are automatically assigned to difficulty levels based on their length:
- Easy: 4 letters or less
- Medium: 5-8 letters
- Hard: 9+ letters
Hangman/
├── hangman.py # Main game code
├── requirements.txt # Python dependencies
├── credentials.json # Firebase credentials (you must create this)
├── README.md # This file
├── images/ # Game images
│ ├── hangman_background.png
│ ├── hangman_background_2.png
│ ├── letter_icon.png
│ ├── 1img.png # Hangman state images
│ ├── 2img.png
│ └── ...
├── database_backup/
├── hangman_DB_export.json
└── rules.txt
- If you see a Firebase initialization error, check your credentials.json file and ensure the databaseURL is correct
- Make sure your Firebase Realtime Database has been initialized and is in the correct region
- Verify that all the required images are in the images/ directory
This project is licensed under the MIT License - see the LICENSE file for details.
When ready to compile the app:
pip install pyinstallerThen run the following command in the terminal:
pyinstaller --windowed \
--name="Hangman" \
--add-data="images:images" \
--add-data="encrypted_credentials.txt:." \
hangman.pyThis will:
- Bundle the encrypted credentials file with your app
- Keep your Firebase credentials secure
- Maintain the full functionality of your app