Skip to content

Instantly share code, notes, and snippets.

@mbvissers
Created February 14, 2022 23:33
Show Gist options
  • Save mbvissers/022856c8c3b91cf902cf54daf06cb796 to your computer and use it in GitHub Desktop.
Save mbvissers/022856c8c3b91cf902cf54daf06cb796 to your computer and use it in GitHub Desktop.
from colorama import init, Fore, Back, Style
import random
init()
loop = True
word_list = ["crown", "build", "logic", "plane", "focus", "money", "plant", "plate", "pound", "other", "input", "horse", "green", "group", "beans", "guide", "layer", "mayor", "lunch", "limit", "model", "point", "scope", "score", "title", "total", "world"]
while loop:
print(Back.WHITE + Fore.BLACK + "Start a new game? (y/quit)" + Style.RESET_ALL)
command = input()
if command == "quit":
loop = False
elif command == "y":
inner_loop = 0
word = random.choice(word_list)
print("Enter a word")
while inner_loop < 6:
attempt = input()
# Game logic
output = ""
for i in range(word.__len__()):
if attempt[i] == word[i]:
output = output + Back.RED + attempt[i] + Back.RESET
elif attempt[i] in word:
output = output + Back.YELLOW + attempt[i] + Back.RESET
else:
output = output + attempt[i] + Back.RESET
print(output)
if word == attempt:
print("Congrats")
inner_loop = inner_loop + 6 # Reset game
inner_loop = inner_loop + 1
@Synxx315
Copy link

from colorama import init, Fore, Back, Style
import random
init()

loop = True
word_list = ["crown", "build", "logic", "plane", "focus", "money", "plant", "plate", "pound", "other", "input", "horse", "green", "group", "beans", "guide", "layer", "mayor", "lunch", "limit", "model", "point", "scope", "score", "title", "total", "world"]
while loop:
print(Back.WHITE + Fore.BLACK + "Start a new game? (y/quit)" + Style.RESET_ALL)
command = input()
if command == "quit":
loop = False
elif command == "y":
inner_loop = 0
word = random.choice(word_list)
print("Enter a word")

    while inner_loop < 6:

        attempt = input()

        # Game logic
        output = ""
        for i in range(word.__len__()):
            if attempt[i] == word[i]:
                output = output + Back.RED + attempt[i] + Back.RESET
            elif attempt[i] in word:
                output = output + Back.YELLOW + attempt[i] + Back.RESET
            else:
                output = output + attempt[i] + Back.RESET
        print(output)
        if word == attempt:
            print("Congrats")
            inner_loop = inner_loop + 6 # Reset game

        inner_loop = inner_loop + 1

@ivlmag
Copy link

ivlmag commented May 30, 2022

Hello! Nice code, very neat and the use of Colorama was a nice touch.

Unfortunately, there are a couple of problems with game engine:

  1. Doesn't check if input is 5 letters long. If you try to enter, for example, a two letter word, game crashes
  2. Doesn't check that input is a real word.
  3. If input word has two (or more) instances of one letter, which is in guessed word, ALL letters would be painted yellow. See screenshot below, both letters T are yellow:

scr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment