Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hints but with added return
  • Loading branch information
pixel-anoel committed Apr 22, 2024
1 parent eba2564 commit 3f916da
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions hangman.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,38 @@

limbs = 0

# Welcome message
print("Welcome to Hangman!")
print("Try to guess the word to save the hanging man!")
print("You have 6 incorrect guesses before the man is fully hung.")
print("Good luck!\n")

# Define a list of hints corresponding to each word in the word list
hints = {
"apple": "A common fruit often red or green.",
"banana": "A yellow fruit that grows in bunches.",
"orange": "A citrus fruit that is round and orange in color.",
# Add more hints for other words as needed
}

def get_hint(word):
# Get the hint corresponding to the given word
return hints.get(word, "No hint available for this word.")















# Setup buttons
increase = round(winWidth / 13)
for i in range(26):
Expand Down Expand Up @@ -208,3 +233,49 @@ def reset():

# always quit pygame when done!
def restart_game():
global limbs
global guessed
global buttons
global word

# Reset all the necessary variables
for i in range(len(buttons)):
buttons[i][4] = True

limbs = 0
guessed = []
word = randomWord()

# MAINLINE
word = randomWord()
inPlay = True

while inPlay:
redraw_game_window()
pygame.time.delay(10)

for event in pygame.event.get():
if event.type == pygame.QUIT:
inPlay = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
inPlay = False
elif event.key == pygame.K_r: # Restart game if 'r' key is pressed
restart_game()
if event.type == pygame.MOUSEBUTTONDOWN:
clickPos = pygame.mouse.get_pos()
letter = buttonHit(clickPos[0], clickPos[1])
if letter != None:
guessed.append(chr(letter))
buttons[letter - 65][4] = False
if hang(chr(letter)):
if limbs != 5:
limbs += 1
else:
end()
else:
print(spacedOut(word, guessed))
if spacedOut(word, guessed).count('_') == 0:
end(True)

pygame.quit()

0 comments on commit 3f916da

Please sign in to comment.