#the code (needs file with words to work) from random import randint from colorama import init, Fore, Back, Style init(autoreset=True) random = randint(0,9973) attempt: int = 6 letters = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я'] work_letters = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я'] with open("words.txt", "r", encoding = "utf-8") as f: file = f.readlines() word = file[random] def game(): """Start the game""" global attempt global letters global lst global work_letters print(' ___________________________________________________________________') print('| |') print(f"|{Fore.RED + ' THE' + Fore.RESET} {Fore.LIGHTRED_EX + 'LETTERS:' + Fore.RESET} |") print('| |') for i in letters: if i == 'А': print('| ' + i, end=' ') elif i == 'Я': print(i, end=' ' + '|') elif i == "\x1b[31mА": print('| ' + i, end=' ') elif i == "\x1b[90mА": print('| ' + i, end= ' ') elif i == "\x1b[31mЯ": print(i, end = ' ' + '|') elif i == "\x1b[90mЯ": print(i, end=' ' + '|') else: print(i, end=' ') print() print('| ________________________________________________|') print(f"| ATTEMPTS LEFT: {Fore.LIGHTCYAN_EX + str(attempt) + Fore.RESET} |") print("| |_________________") print("| |") print(f"| WRITE A {Fore.LIGHTMAGENTA_EX + 'FIVE-LETTER' + Fore.RESET} {Fore.CYAN + 'WORD' + Fore.RESET} FOR CHECK!|") print(" ____________________________________") with open("words.txt", "r", encoding="utf-8") as f2: file2 = f2.readlines() print() player_input = input() print() if f"{player_input.lower()}\n" in file2: if f"{player_input.lower()}\n" != word: attempt -= 1 if attempt == 0: print( f"YOU DIDN'T GUESS. THE WORD WAS {Fore.LIGHTYELLOW_EX + word[0:-1].upper() + Fore.RESET} {Fore.BLACK + ':(' + Fore.RESET}") print( f"\nDO YOU NEED TO CONTINUE? ({Fore.LIGHTWHITE_EX + 'YES' + Fore.RESET}/{Fore.LIGHTBLACK_EX + 'NO' + Fore.RESET})\n") chose(input().upper()) else: for i in player_input.lower(): if i in word: if i.upper() in work_letters: index = letters.index(i.upper()) letters[index] = Fore.RED + letters[index] work_letters.remove(i.upper()) else: pass else: if i.upper() in work_letters: index = letters.index(i.upper()) letters[index] = Fore.LIGHTBLACK_EX + letters[index] work_letters.remove(i.upper()) else: pass print() game() else: ansi_red = "\x1b[31m" ansi_gray = "\x1b[90m" for i in letters: if i == ansi_red + i[-1]: letters[letters.index(i)] = Fore.LIGHTYELLOW_EX + i[-1].upper() elif i == ansi_gray + i[-1]: pass else: if i.lower() in word: letters[letters.index(i)] = Fore.LIGHTYELLOW_EX + i.upper() else: pass print() for i in letters: print(i, end=' ') print() print() print(f"\n{Fore.YELLOW + 'CONGRATULATIONS!' + Fore.RESET} YOU GUESSED THE WORD - {Fore.LIGHTYELLOW_EX + word[0:-1]}\n") print(f"\nDO YOU NEED TO CONTINUE? ({Fore.LIGHTWHITE_EX + 'YES' + Fore.RESET}/{Fore.LIGHTBLACK_EX + 'NO' + Fore.RESET})\n") chose(input().upper()) else: print(f"\nTHERE IS NO SUCH WORD, {Fore.LIGHTWHITE_EX + Back.LIGHTRED_EX + Style.BRIGHT +'TRY AGAIN!' + Style.RESET_ALL + Back.RESET}\n") game() def chose(chose_input: str): """Player chose""" global letters global work_letters global attempt match chose_input: case "YES": print() print(f"\n{Back.BLACK + Fore.LIGHTYELLOW_EX + 'GOOD LUCK IN NEW GAME ! :D' + Back.RESET}\n") print() letters = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я'] work_letters = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я'] attempt = 6 game() case "NO": print(f"\n{Fore.MAGENTA + 'THANKS' + Fore.RESET}, THAT YOU SPENT TIME FOR THIS GAME! {Fore.LIGHTYELLOW_EX + 'GOOD LUCK!'} {Fore.BLACK + 'XD'}") exit() case _: print(f"\nI DONT UNDERSTAND! {Fore.LIGHTYELLOW_EX + Back.BLACK + 'TRY AGAIN' + Fore.RESET + Back.RESET} {Back.LIGHTYELLOW_EX + Fore.BLACK + '!!!' + Back.RESET + Fore.RESET}\n") chose(input().upper()) def chose_two(ch_inp: str): match ch_inp: case "GAME": print() print(f"\n{Fore.LIGHTYELLOW_EX + 'GOOD LUCK!' + Fore.RESET + Fore.BLACK + ' :D'}\n") game() case "game": print() print(f"\n{Fore.LIGHTYELLOW_EX + 'GOOD LUCK!' + Fore.RESET + Fore.BLACK + ' :D'}\n") game() case "RULES": print() print(f"\n{Back.BLACK + Fore.LIGHTWHITE_EX + '1' + Back.RESET + Fore.RESET}. {Fore.RED + 'THE RED COLOUR' + Fore.RESET} IS SO THAT YOU GUESSED RIGHT THE LETTER IN GUESSED WORD\n") print(f"{Back.BLACK + Fore.LIGHTWHITE_EX + '2' + Back.RESET + Fore.RESET}. {Fore.LIGHTBLACK_EX + 'THE BLACK COLOUR' + Fore.RESET} IS SO THAT LETTTER THIS COLOUR NO IN GUESSED WORD\n") print(f"{Back.BLACK + Fore.LIGHTWHITE_EX + '3' + Back.RESET + Fore.RESET}. {Fore.LIGHTYELLOW_EX + 'THE YELLOW COLOUR' + Fore.RESET} IS PRINT WHEN YOU GUESSED RIGHT WORD\n") print() game() case "rules": print() print( f"\n{Back.BLACK + Fore.LIGHTWHITE_EX + '1' + Back.RESET + Fore.RESET}. {Fore.RED + 'THE RED COLOUR' + Fore.RESET} IS SO THAT YOU GUESSED RIGHT THE LETTER IN GUESSED WORD\n") print( f"{Back.BLACK + Fore.LIGHTWHITE_EX + '2' + Back.RESET + Fore.RESET}. {Fore.LIGHTBLACK_EX + 'THE BLACK COLOUR' + Fore.RESET} IS SO THAT LETTTER THIS COLOUR NO IN GUESSED WORD\n") print( f"{Back.BLACK + Fore.LIGHTWHITE_EX + '3' + Back.RESET + Fore.RESET}. {Fore.LIGHTYELLOW_EX + 'THE YELLOW COLOUR' + Fore.RESET} IS PRINT WHEN YOU GUESSED RIGHT WORD\n") print() game() case _: print(f"\nI DON'T UNDERSTAND! {Fore.LIGHTYELLOW_EX + Back.BLACK + 'TRY AGAIN ' + Fore.RESET + Fore.LIGHTBLUE_EX + ';' + Fore.RESET + Fore.LIGHTRED_EX + '(' + Back.RESET}\n") chose_two(input()) print(f"\nWELCOME TO GAME {Fore.LIGHTYELLOW_EX + 'W'+Fore.RESET + Fore.RED + 'O' + Fore.RESET + Fore.LIGHTMAGENTA_EX + 'R' + Fore.RESET + Fore.LIGHTCYAN_EX + 'D' + Fore.RESET + Fore.LIGHTRED_EX + 'L' + Fore.RESET + Fore.LIGHTGREEN_EX + 'E' + Fore.RESET}\n") print(f"WHAT ARE YOU WANT? {Fore.LIGHTRED_EX + 'GAME' + Fore.RESET}/{Fore.LIGHTGREEN_EX + 'RULES' + Fore.RESET}\n") chose_two(input())