diff --git a/hangman.py b/hangman.py index 2dffd42..8896d38 100644 --- a/hangman.py +++ b/hangman.py @@ -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): @@ -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()