Hangman | A simple hangman game made with python and pygame | Game Engine library
kandi X-RAY | Hangman Summary
kandi X-RAY | Hangman Summary
A simple hangman game made with python and pygame. This was made as a beginner pygame project in grade 11 (2017).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- End the game
- Redraw the game window
- Return a fixed word out of a word
- Reset the robot
- Return a random word
- Redraw the game window
- Get a random word
- Returns the button with the given coordinates
Hangman Key Features
Hangman Examples and Code Snippets
def display_hangman(tries):
stages = ["""
--------
| |
| 0
| \\|/
| |
| / \\
-
Community Discussions
Trending Discussions on Hangman
QUESTION
`difficulty = ""
while difficulty != "e", difficulty != "m", difficulty != "h":
difficulty = input("Select your difficulty: [e]asy, [m]edium, [h]ard: ").lower()`
...ANSWER
Answered 2021-Jun-15 at 01:50@Samuel Zewdu Here is the correct code you are looking for:
QUESTION
I was trying to do a hangman game, my idea was that you give the number of letters and the word, then the program fills a char with _
as letters the word has. Then it asks you a letter and it compares if the letter matches any letter in the word given. Then it replaces the respective _
with the letter, but it doesn't replace it...
What am I doing wrong?
...ANSWER
Answered 2021-Jun-08 at 20:16int n = 0;
char blank[n - 1];
QUESTION
I am trying to make a Hangman game in Python, and I'm having some trouble with a certain function. Before I work on the game itself, I need to make some functions.
The last one I need to make is a function that will receive a file path to a txt file that contains words separated by space, and it will receive a number that represents the index of a certain word. The function need to return a tuple made of two parts:
- the number of unique words in the file, meaning excluding the words that repeat themselves.
- the word in the index that was received, that will be used for the secret word.
The index that the player inputs needs to start from 1 and not 0, and if the index is bigger than the number of words in the file, the function will continue to count in a circular manner (meaning, when it comes back to the first word in the file).
Here is an example of a file with words called words.txt:
'''hangman song most broadly is a song hangman work music work broadly is typically'''
And here is how the function should run:
...ANSWER
Answered 2021-Jun-12 at 21:02You can use modulo (%
) to calculate the index, like so:
QUESTION
I am having trouble figuring out how to do the hangman display in my python hangman game. How my current code is working under my display_word function is that it will show a '-' for any word that is my hangman word. When I guess a letter correct it will shorten the '-' display by the number of letter are in the string. I would like instead for this display to add that letter to the display and still hold the '-''s for the letters I haven't guessed. Can anyone solve this?
...ANSWER
Answered 2021-Jun-08 at 20:43I think you are making this much harder than it needs to be. For each letter, if it was guessed, print the letter, otherwise print a dash. No replacing required.
QUESTION
I am trying to loop over my hangman project but cannot seem to figure out a way without creating an infinite loop. I want to avoid having to ask for user input in multiple places in my guess function and be able to put it in in one place. I feel like I have all the logic down, I would just need to figure out the looping portion. How can I solve this?
...ANSWER
Answered 2021-Jun-08 at 17:58You could amend check_win()
to return true when guessed correctly:
QUESTION
I am trying to make the game "Hangman" and here is my code. in my code I have a variable called hangman_status=0
and I want to increase in when the user guesses wrongly and the picture related to that each time but code is not doing this I would be happy if you helped me understand what is the problem.
My code :
...ANSWER
Answered 2021-Jun-05 at 18:22You need to change the images
varaible when hangman_status
changes:
QUESTION
I recently started making hangman, and in one of the parts i have to replace a underscore with a letter, which i cant for some reason.
...ANSWER
Answered 2021-Jun-03 at 18:51The underscore[word.index(letter)+1]
will resolve into the character "_" and therefore it replaces all those with letter
.
One solution can be that you keep underscore
as a list instead and then assign by index
QUESTION
import os
import random
import time
import math
def stringmanipulator(xy, y=40):
xy= xy.lower()
x = []
x = list(xy)
length = len(x)
y = int(math.floor(length * (y/100)))
while(y):
r =int(random.random()*(length-1))
if(x[r] != '_' and x[r] != ' '):
x[r] = '_'
y = y-1
return x
def printcomplement():
x = int(random.random()*11)
if(x == 0):
print("well done!!")
elif(x == 1):
print("keep going!!")
elif(x == 2):
print("YOU can save him!!")
elif(x == 3):
print("You are the hero no one wanted but everyone deserves.")
elif(x == 4):
print("Genius kid.")
elif(x == 5):
print("You are Smart, not kidding.")
elif(x == 6):
print("You are one who will destroy my carrer using your intellect.")
elif(x == 7):
print("The most kind hearted person I have ever seen till now. Yes I am talking about you")
elif(x == 8):
print("You nailed it.")
elif(x == 9):
print("AND I thought the game was hard.")
elif(x == 10):
print("I will find more difficult words to challenge you with.")
elif(x == 11):
print("How about you put another life on risk after this round.")
def printdis():
x = int(random.random()*11)
if(x == 0):
print("Fool")
elif(x == 1):
print("You will end up killing the fool and then I will hang you next.")
elif(x == 2):
print("What a piece of shit you are.")
elif(x == 3):
print("Hey disgrace to humanity.")
elif(x == 4):
print("Don't cry after the man is dead. You killed him, I gave you a chance to save him.")
elif(x == 5):
print("Dumbass!!")
elif(x == 6):
print("You know what it was my mistake to let such an idiot play.")
elif(x == 7):
print("This is your last game. I don't want fools playing this game.")
elif(x == 8):
print("I see you are already crying.")
elif(x == 9):
print("Even the guy who's life is line is laughing at your stupidity.")
elif(x == 10):
print("My 120 years old grandma has a sharper brain than yours.")
elif(x == 11):
print("Get lost, YOU useless, moronic, unworthy pile of garbage.")
def hangman(i = 0):
if(i == 0):
print("___________")
print("| |")
print("| |")
print("| ")
print("| ")
print("| ")
print("| ")
print("| ")
print("|")
elif(i == 1):
print("___________")
print("| |")
print("| |")
print("| ( ) ")
print("| ")
print("| ")
print("| ")
print("| ")
print("|")
elif(i == 2):
print("___________")
print("| |")
print("| |")
print("| ( ) ")
print("| | ")
print("| | ")
print("| ")
print("| ")
print("|")
elif(i == 3):
print("___________")
print("| |")
print("| |")
print("| ( ) ")
print("| \\ | / ")
print("| | ")
print("| ")
print("| ")
print("|")
elif(i == 4):
print("___________")
print("| |")
print("| |")
print("| \\ ( ) /")
print("| \\ | / ")
print("| ")
print("| ")
print("| ")
print("|")
elif(i == 5):
print("___________")
print("| |")
print("| |")
print("| \\ ( ) /")
print("| \\ | / ")
print("| | ")
print("| / \\")
print("| ")
print("|")
elif(i == 6):
print("___________")
print("| |")
print("| |")
print("| \\ ( ) /")
print("| \\ | / ")
print("| | ")
print("| / \\")
print("| / \\")
print("|")
print("\n\nGAME OVER. You have succesfully killed a person. Better luck next time")
def game(xy, y):
x=[]
i = 0
letter = ''
x = stringmanipulator(xy, y)
xy = xy.lower()
# os.system('cls')
for index in range(len(x)):
if(x[index] == '_'):
while(letter != x[index]):
_= os.system('cls')
hangman(i)
for char in range(len(x)):
print(x[char], end=' ')
print("\n")
letter = input("Enter the letter in the first blank: ")
print(letter+str(i))
if(letter == xy[index]):
print("complement")
x[index] = letter
else:
printdis()
i+=1
dictionary ={}
dictionary["films"] = ["A Space OdysseY", "The GodFather", "Citizen Kane", "Raiders of the lost Ark", "Seven Samurai", "There will be Blood", "Casablanca", "Vertigo", "Notorious", "City Lights"]
dictionary["cities"] = ["Tokyo", "Mecca", "Beijing", "London", "Kolkata", "Washington DC", "Mumbai", "Mexico City", "Delhi", "Shanghai"]
dictionary["fruits"] = ["Damson Plum", "Pomelo", "Blood Orange", "Kumquat", "Blackcurrant", "Acerola", "Avocado", "Pomegrenate", "Apple", "Mango"]
dictionary["country"] = ["Djibouti", "Azerbaijan Azerbaijan,", "Venzuela", "Armenia", "Khazakhstan", "Bangladesh", "Saudi Arabia", "United Kingdom", "United States of America", "India"]
dictionary["flowers"] = ["Monkey Face Orchid", "Naked Man Orchid", "Dancing Girls", "Chamber Maids", "Hibiscus", "Marigold", "Tulip", "Lilies", "Daisy", "Hydrangea"]
print("WELCOME TO THE GAME HANGMAN.\n TAKE THE GAME SERIOUSLY SINCE THE LIFE OF A MAN IS DEPENDING ON YOUR KNOWLEDGE. \n\nI DON'T KNOW HOW MANY CHANCE YOU WILL GET, NOT MANY THAT I CAN CONFIRM.\n SO TRY TO SAVE YOUR FELLOW HUMAN OR LET IT BE MY FOOD. HAHAHAHAHAHAHAHAHAH!!!!!!!")
# x = input("Press 1 for films, 2 for cities, 3 for fruits, 4 for country and 5 for flowers (The most beautiful are usually the hardest): ")
# x = int(x)
x = int(input("Enter a number between 1 and 5: "))
if((x < 1) or(x > 5)):
print("What a moron you are. You couldn't even choose one of the option properly game over good bye, tata, cya")
x = random.randint(1,5)
time.sleep(10)
print("Just kidding you still get to play the game but now I will decide what kind of object you have to guess.")
y = int(input("Enter 40 for easy, 60 for medium and 80 for hard: "))
i = 0
xy = ""
r = random.randint(0,9)
if(x == 1):
xy = dictionary["films"][r]
print("FILMS:")
elif(x == 2):
xy = dictionary["cities"][r]
print("CITIES:")
elif(x == 3):
xy = dictionary["fruits"][r]
print("FRUITS:")
elif(x == 4):
xy = dictionary["country"][r]
print("COUNTRY:")
elif(x == 5):
xy = dictionary["flowers"][r]
print("FLOWERS:")
# hangman(0)
game(xy, y)
...ANSWER
Answered 2021-May-31 at 14:43Running your code os.system('cls') is clearing the screen before the input is read in the loop. This makes it seem that there is no output is being displayed when it's really being overwritten.
A quick test can be done to confirm that this is the problem. To do this we add another input read in the game function. like so:
QUESTION
My goal is to create a basic hangman game using the random
and tkinter
libraries.
1. The goal of the program is to choose one random word (from an array).
2. Then the program replaces the letters in the word with "_".
3. This word will start falling down from the top edge to the bottom edge using an animation.
4. While the word is falling down, our goal is to guess the right word by pressing letters on the keyboard.
5. If the letter we've pressed is in the word the program picked, the '_' gets replaced with the letter.
So far I've created the canvas, the animation, replaced the letters with underscores, and created an array of words from where the program can pick.
How can I make the letter detection? For an instance, if I press "F" and the letter is in the word the program has picked, the '_' should get replaced with the letter.
My code so far
...ANSWER
Answered 2021-May-08 at 19:54You can bind event with function which will check what was pressed and it will replace text on canvas.
QUESTION
I am new to JavaScript and i have project in which I have to make a hangman game. I have already built a function that replace _
with correct answers.
If password is "MOM":
if you guess M
then you have M _ M
,
if you guess O
then you have _ O _
,
if you guess L
then you have _ _ _
.
But I don't know how to make tat user cannot guess the same character the twice. here is my Code:
...ANSWER
Answered 2021-May-31 at 10:26Create an array 'guesses' and before executing the loop check if the char is inside 'guesses':
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Hangman
You can use Hangman like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page