Skip to content

Commit

Permalink
Merge pull request #352 from Aditijainnn/Hangman-game
Browse files Browse the repository at this point in the history
Added hangman game
  • Loading branch information
UTSAVS26 authored Oct 9, 2024
2 parents 064ee97 + 47ad2cc commit c435cf2
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Game_Development/Hangman-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Hangman Game 🎮

## 🎯 Objective

Here’s a more elaborate game called "Hangman Game" using Python's Tkinter library. In this classic Hangman game, your goal is to guess the hidden word one letter at a time. You have a limited number of incorrect guesses before the game is over, so choose wisely!
---

**Prerequisite**:Install `pthon`

Before running the code, you need to install the `python`

## 🚀 How to Play:

- The game selects a random word.
- You have to guess the word one letter at a time.
- You can make a limited number of wrong guesses before the
stickman is "hanged".
- Each correct guess reveals the letter(s) in the word.
- The game ends when you either guess the word or run out of
guesses.

---

## 🔧 How to Run

1. Clone the repository and navigate to the project folder:
```bash
git clone <repository-url>
cd <project-folder>
```

2. Install dependencies (if any) and then run the program:
```bash
python hangman.py
```

3. Enjoy playing the Snake game!

---

67 changes: 67 additions & 0 deletions Game_Development/Hangman-main/hangman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from tkinter import *
from tkinter import messagebox
from string import ascii_uppercase
import random


window = Tk()
window.title('Hangman-GUESS CITIES NAME')
word_list= ['MUMBAI','DELHI','BANGLORE','HYDRABAD','AHMEDABAD','CHENNAI','KOLKATA','SURAT','PUNE','JAIPUR','AMRITSAR','ALLAHABAD','RANCHI',
'LUCKNOW','KANPUR','NAGPUR','INDORE','THANE','BHOPAL','PATNA','GHAZIABAD','AGRA','FARIDABAD','MEERUT','RAJKOT','VARANASI','SRINAGAR',
'RAIPUR','KOTA','JHANSI']

photos = [PhotoImage(file="images/hang0.png"), PhotoImage(file="images/hang1.png"), PhotoImage(file="images/hang2.png"),
PhotoImage(file="images/hang3.png"), PhotoImage(file="images/hang4.png"), PhotoImage(file="images/hang5.png"),
PhotoImage(file="images/hang6.png"), PhotoImage(file="images/hang7.png"), PhotoImage(file="images/hang8.png"),
PhotoImage(file="images/hang9.png"), PhotoImage(file="images/hang10.png"), PhotoImage(file="images/hang11.png")]






def newGame():
global the_word_withSpaces
global numberOfGuesses
numberOfGuesses =0

the_word=random.choice(word_list)
the_word_withSpaces = " ".join(the_word)
lblWord.set(' '.join("_"*len(the_word)))

def guess(letter):
global numberOfGuesses
if numberOfGuesses<11:
txt = list(the_word_withSpaces)
guessed = list(lblWord.get())
if the_word_withSpaces.count(letter)>0:
for c in range(len(txt)):
if txt[c]==letter:
guessed[c]=letter
lblWord.set("".join(guessed))
if lblWord.get()==the_word_withSpaces:
messagebox.showinfo("Hangman","You guessed it!")
else:
numberOfGuesses += 1
imgLabel.config(image=photos[numberOfGuesses])
if numberOfGuesses==11:
messagebox.showwarning("Hangman","Game Over")


imgLabel=Label(window)
imgLabel.grid(row=0, column=0, columnspan=3, padx=10, pady=40)



lblWord = StringVar()
Label(window, textvariable =lblWord,font=('consolas 24 bold')).grid(row=0, column=3 ,columnspan=6,padx=10)

n=0
for c in ascii_uppercase:
Button(window, text=c, command=lambda c=c: guess(c), font=('Helvetica 18'), width=4).grid(row=1+n//9,column=n%9)
n+=1

Button(window, text="New\nGame", command=lambda:newGame(), font=("Helvetica 10 bold")).grid(row=3, column=8)

newGame()
window.mainloop()
Binary file added Game_Development/Hangman-main/images/hang0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game_Development/Hangman-main/images/hang9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c435cf2

Please sign in to comment.