Fixes and Changes #1

Merged
wholesomedonut merged 3 commits from timemachine/pystermind:master into master 2020-09-15 19:30:23 +00:00
1 changed files with 20 additions and 9 deletions
Showing only changes of commit 30f54f438f - Show all commits

29
main.py
View File

@ -41,6 +41,10 @@ and what you got wrong.
* = correct color in correct location
~ = correct color and wrong location
# = incorrect color in incorrect location
'?' for help.
'q' to quit.
"""
@ -61,7 +65,6 @@ def checkGuess(guess):
raise LengthException("Your guess is too short.")
for i in guess:
print('i:', i)
if i not in colors:
raise ColorException("You are not guessing from r, g, b, or y.")
@ -85,11 +88,7 @@ def compare(secret, guess, clue):
def calc(secret, guess, clue):
tmp = ''
if tmp.join(clue) == '****':
print('You won!')
else:
print('Not quite right.')
print('Your clue:', clue)
return tmp.join(clue) == '****'
generateSecret(secret)
@ -98,7 +97,7 @@ print(rules)
while game_continue:
guess = []
temp = input('Choose your colors. Input \'?\' for help: ')
temp = input('Choose your colors: ')
if debug:
print('Temp =', temp)
guess = list(temp)
@ -119,24 +118,36 @@ while game_continue:
# Will obviously continue if you don't quit.
win = False
try:
if game_continue:
checkGuess(guess)
clue = compare(secret, guess, clue)
# Finds differences between guess and secret
calc(secret, guess, clue)
win = calc(secret, guess, clue)
# Calculates if you won or not and outputs it.
if win:
print('You won!')
else:
print('Not quite right.')
clue_string = ''.join(clue)
print('Your clue: ', clue_string)
continue
except LengthException as e:
print('Error:', e)
continue
except ColorException as e:
print('Error:', e)
continue
cont = input('Try again? y/n: ')
if cont == 'y': # Regenerates secret and clears variables.
secret = []
generateSecret(secret)
guess = []
elif cont == 'n':
game_continue = False
print('Bye!')