|
|
@ -1,11 +1,13 @@
|
|
|
|
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import random
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getGuess():
|
|
|
|
def getGuess(number):
|
|
|
|
validGuess = False
|
|
|
|
validGuess = False
|
|
|
|
guess = ""
|
|
|
|
guess = ""
|
|
|
|
while not validGuess:
|
|
|
|
while not validGuess:
|
|
|
|
guess = str(input("Please guess:")).upper()
|
|
|
|
guess = str(input("Guess " + str(number) + " / 6: ")).upper()
|
|
|
|
if len(guess) > 5 or len(guess) < 5:
|
|
|
|
if len(guess) > 5 or len(guess) < 5:
|
|
|
|
print("Invalid guess - please ensure you're guessing a word of 5 letters")
|
|
|
|
print("Invalid guess - please ensure you're guessing a word of 5 letters")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -13,8 +15,14 @@ def getGuess():
|
|
|
|
return guess
|
|
|
|
return guess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get absolute path to resource - works when run from script and compiled using PyInstaller
|
|
|
|
|
|
|
|
def resource_path(relative_path):
|
|
|
|
|
|
|
|
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
|
|
return os.path.join(base_path, relative_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getWord():
|
|
|
|
def getWord():
|
|
|
|
lines = open('words.txt').read().splitlines()
|
|
|
|
lines = open(resource_path('words.txt')).read().splitlines()
|
|
|
|
return random.choice(lines)
|
|
|
|
return random.choice(lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -25,15 +33,26 @@ def checkRight(wordToGuess, guessSoFar):
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def header():
|
|
|
|
|
|
|
|
return r" ______ ______ _ _____" + "\n" + \
|
|
|
|
|
|
|
|
r"| _ \ \ / / _ \| | | ____|" + "\n" + \
|
|
|
|
|
|
|
|
r"| |_) \ V /| | | | | | _|" + "\n" + \
|
|
|
|
|
|
|
|
r"| __/ | | | |_| | |___| |___" + "\n" + \
|
|
|
|
|
|
|
|
r"|_| |_| |____/|_____|_____|"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Welcome to...")
|
|
|
|
|
|
|
|
print(header())
|
|
|
|
|
|
|
|
print("A totally original guessing game!")
|
|
|
|
emptyWordGuess = ["_"] * 5
|
|
|
|
emptyWordGuess = ["_"] * 5
|
|
|
|
wrongLetters = set()
|
|
|
|
wrongLetters = set()
|
|
|
|
rightLettersWrongPlace = set()
|
|
|
|
rightLettersWrongPlace = set()
|
|
|
|
wordToGuess = list(getWord().upper())
|
|
|
|
wordToGuess = list(getWord().upper())
|
|
|
|
# print(wordToGuess)
|
|
|
|
# print(wordToGuess)
|
|
|
|
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
counter = 1
|
|
|
|
while counter < 5:
|
|
|
|
while counter < 6:
|
|
|
|
userGuess = getGuess()
|
|
|
|
userGuess = getGuess(counter)
|
|
|
|
emptyWordGuess = ["_"] * 5
|
|
|
|
emptyWordGuess = ["_"] * 5
|
|
|
|
for i in range(len(userGuess)):
|
|
|
|
for i in range(len(userGuess)):
|
|
|
|
if wordToGuess[i] == userGuess[i]:
|
|
|
|
if wordToGuess[i] == userGuess[i]:
|
|
|
|