|
|
@ -3,6 +3,7 @@ import random
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Gets the input from a user - number param is used to display the guess number the user is on
|
|
|
|
def get_guess(number):
|
|
|
|
def get_guess(number):
|
|
|
|
validGuess = False
|
|
|
|
validGuess = False
|
|
|
|
guess = ""
|
|
|
|
guess = ""
|
|
|
@ -61,14 +62,10 @@ def game_over(user_was_right, correct_word):
|
|
|
|
sys.exit(0)
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Main game flow.
|
|
|
|
# Takes in the users guess and the myriad lists involved in the game logic, and compares the letters in the guess
|
|
|
|
def game_logic():
|
|
|
|
# with the word to be guessed.
|
|
|
|
not_in_word, present_in_word = set(), set()
|
|
|
|
# Inserts the letter into the appropriate list, based on its presence & position (or lack thereof)
|
|
|
|
word_to_be_guessed = list(get_random_word().upper())
|
|
|
|
def check_letter_in_word(users_guess_input, word_to_be_guessed, users_guess_results, present_in_word, not_in_word):
|
|
|
|
counter = 1
|
|
|
|
|
|
|
|
while counter < 7:
|
|
|
|
|
|
|
|
users_guess_input = get_guess(counter)
|
|
|
|
|
|
|
|
users_guess_results = ["_"] * 5
|
|
|
|
|
|
|
|
for i in range(len(users_guess_input)):
|
|
|
|
for i in range(len(users_guess_input)):
|
|
|
|
if word_to_be_guessed[i] == users_guess_input[i]:
|
|
|
|
if word_to_be_guessed[i] == users_guess_input[i]:
|
|
|
|
users_guess_results[i] = users_guess_input[i]
|
|
|
|
users_guess_results[i] = users_guess_input[i]
|
|
|
@ -79,6 +76,17 @@ def game_logic():
|
|
|
|
present_in_word.add(users_guess_input[i])
|
|
|
|
present_in_word.add(users_guess_input[i])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
not_in_word.add(users_guess_input[i])
|
|
|
|
not_in_word.add(users_guess_input[i])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Main game flow.
|
|
|
|
|
|
|
|
def game_logic():
|
|
|
|
|
|
|
|
not_in_word, present_in_word = set(), set()
|
|
|
|
|
|
|
|
word_to_be_guessed = list(get_random_word().upper())
|
|
|
|
|
|
|
|
counter = 1
|
|
|
|
|
|
|
|
while counter < 7:
|
|
|
|
|
|
|
|
users_guess_input = get_guess(counter)
|
|
|
|
|
|
|
|
users_guess_results = ["_"] * 5
|
|
|
|
|
|
|
|
check_letter_in_word(users_guess_input, word_to_be_guessed, users_guess_results, present_in_word, not_in_word)
|
|
|
|
if check_word_is_right(word_to_be_guessed, users_guess_results):
|
|
|
|
if check_word_is_right(word_to_be_guessed, users_guess_results):
|
|
|
|
game_over(True, word_to_be_guessed)
|
|
|
|
game_over(True, word_to_be_guessed)
|
|
|
|
print("Incorrect letters: " + ', '.join(not_in_word))
|
|
|
|
print("Incorrect letters: " + ', '.join(not_in_word))
|
|
|
|