Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

test

import random
import time
import sys
import os

if os.name == 'nt':
    from ctypes import windll
    k = windll.kernel32
    k.SetConsoleMode(k.GetStdHandle(-11), 7)

keys = {'a': 'NSr', 'b': 'rlK', 'c': 'yDD', 'd': 'YBr', 'e': 'XBB', 'f': 'LLo', 'g': 'gZn', 'h': 'LTd', 'i': 'hKn', 'j': 'fWj', 'k': 'dgu', 'l': 'nFN', 'm': 'nNy',
        'n': 'QKD', 'o': 'cJJ', 'p': 'MEA', 'q': 'WTJ', 'r': 'nnM', 's': 'Tru', 't': 'xcE', 'u': 'Msx', 'v': 'Cef', 'w': 'Hkf', 'x': 'obn', 'y': 'myp', 'z': 'PUE'}

keyr = {v: k for k, v in keys.items()}

def encrypt(text):
  if len(text) > 1:
    string = ""
    for char in text:
      if char in keys:
        string += keys[char] + ","
      else:
        return "Only letters are allowed"
        break
    return string
  else:
    return "Text must have something in it"

def decrypt(text):
  text = text[:-1].split(",")
  if len(text) > 1:
    string = ""
    for char in text:
      if char in keyr:
        string += keyr[char]
      else:
        return "Only letters are allowed"
        break
    return string
  else:
    return "Text must have something in it"

print("Welcome to Wordle!")
print("Random or Custom Word?")
ch = input("Type 'r' or 'c' ")

if ch not in ("r", "c"):
  while ch not in ("r", "c"):
    ch = input("Type 'r' or 'c' ")

green = "u001b[32m"
yellow = "u001b[33m"
reset = "u001b[0m"

if ch == "r":
  letters = "abcdefghijklmnopqrstuvwxyz"
  ln = {}
  for char in letters:
    ln[char] = 0
  words = open("words.txt", "r")
  wordl = []
  for item in words.readlines():
    wordl.append(item.strip())
  word = wordl[random.randint(0, 5756)]
  print(f'Your word is 5 letters. Start guessing!')
  num = 1
  correct = False
  while num < 6:
    guess = input(f'Guess {str(num)}: ').lower()
    sys.stdout.write("33[F")
    invalid = False
    for char in guess:
      if char not in keys:
        print(" " * 250)
        sys.stdout.write("33[F")
        print("Must be only letters!")
        invalid = True
    if len(guess) > 5:
      print(" " * 250)
      sys.stdout.write("33[F")
      print("Word is too long.")
    elif len(guess) < 5:
      print(" " * 250)
      sys.stdout.write("33[F")
      print("Word is too short.")
    elif guess not in wordl:
      print(" " * 250)
      sys.stdout.write("33[F")
      print("Invalid word.")
    elif invalid:
      pass
    else:
      if guess == word:
        print("Your word is correct!")
        correct = True
        break
      chn = 0
      colored = ""
      for char in guess:
        if char in word:
          if char == word[chn]:
            colored += f'{green}{char}{reset}'
          else:
            colored += f'{yellow}{char}{reset}'
        else:
          colored += char
        chn += 1
      print(f'Guess {str(num)}: ' + colored)
      num += 1
  if correct == False:
    print(f'You lose! The word was {word}. Better luck next time!')
  else:
    print("Congratulations! You win!")
  time.sleep(999)
  
  
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #test
ADD COMMENT
Topic
Name
7+3 =