mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 15:37:51 -08:00
Make all variable names snake_case for consistency
This commit is contained in:
@@ -132,61 +132,61 @@ words = ["GUM", "SIN", "FOR", "CRY", "LUG", "BYE", "FLY",
|
|||||||
"MATRIMONIAL", "PARASYMPATHOMIMETIC", "THIGMOTROPISM"]
|
"MATRIMONIAL", "PARASYMPATHOMIMETIC", "THIGMOTROPISM"]
|
||||||
|
|
||||||
|
|
||||||
def play_game(guessTarget):
|
def play_game(guess_target):
|
||||||
"""Play the game"""
|
"""Play the game"""
|
||||||
guessWrong = 0
|
guess_wrong = 0
|
||||||
guessProgress = ["-"] * len(guessTarget)
|
guess_progress = ["-"] * len(guess_target)
|
||||||
guessList = []
|
guess_list = []
|
||||||
|
|
||||||
gallows = Canvas()
|
gallows = Canvas()
|
||||||
draw_gallows(gallows)
|
draw_gallows(gallows)
|
||||||
|
|
||||||
guessCount = 0
|
guess_count = 0
|
||||||
while True:
|
while True:
|
||||||
print("Here are the letters you used:")
|
print("Here are the letters you used:")
|
||||||
print(",".join(guessList) + "\n")
|
print(",".join(guess_list) + "\n")
|
||||||
print("".join(guessProgress) + "\n")
|
print("".join(guess_progress) + "\n")
|
||||||
guessLetter = ""
|
guess_letter = ""
|
||||||
guessWord = ""
|
guess_word = ""
|
||||||
while guessLetter == "":
|
while guess_letter == "":
|
||||||
guessLetter = input("What is your guess? ").upper()[0]
|
guess_letter = input("What is your guess? ").upper()[0]
|
||||||
if not guessLetter.isalpha():
|
if not guess_letter.isalpha():
|
||||||
guessLetter = ""
|
guess_letter = ""
|
||||||
print("Only letters are allowed!")
|
print("Only letters are allowed!")
|
||||||
elif guessLetter in guessList:
|
elif guess_letter in guess_list:
|
||||||
guessLetter = ""
|
guess_letter = ""
|
||||||
print("You guessed that letter before!")
|
print("You guessed that letter before!")
|
||||||
guessList.append(guessLetter)
|
guess_list.append(guess_letter)
|
||||||
guessCount = guessCount + 1
|
guess_count = guess_count + 1
|
||||||
if guessLetter in guessTarget:
|
if guess_letter in guess_target:
|
||||||
indices = [i for i, letter in enumerate(guessTarget) if letter == guessLetter]
|
indices = [i for i, letter in enumerate(guess_target) if letter == guess_letter]
|
||||||
for i in indices:
|
for i in indices:
|
||||||
guessProgress[i] = guessLetter
|
guess_progress[i] = guess_letter
|
||||||
if guessProgress == guessTarget:
|
if guess_progress == guess_target:
|
||||||
print("You found the word!")
|
print("You found the word!")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("\n" + "".join(guessProgress) + "\n")
|
print("\n" + "".join(guess_progress) + "\n")
|
||||||
while guessWord == "":
|
while guess_word == "":
|
||||||
guessWord = input("What is your guess for the word? ").upper()
|
guess_word = input("What is your guess for the word? ").upper()
|
||||||
if not guessWord.isalpha():
|
if not guess_word.isalpha():
|
||||||
guessWord = ""
|
guess_word = ""
|
||||||
print("Only words are allowed!")
|
print("Only words are allowed!")
|
||||||
if guessWord == guessTarget:
|
if guess_word == guess_target:
|
||||||
print("Right!! It took you", guessCount, "guesses!")
|
print("Right!! It took you", guess_count, "guesses!")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
comment, drawingBodyPart = PHASES[guessWrong]
|
comment, draw_bodypart = PHASES[guess_wrong]
|
||||||
|
|
||||||
print(comment)
|
print(comment)
|
||||||
drawingBodyPart(gallows)
|
draw_bodypart(gallows)
|
||||||
print(gallows.render())
|
print(gallows.render())
|
||||||
|
|
||||||
guessWrong = guessWrong + 1
|
guess_wrong = guess_wrong + 1
|
||||||
print("Sorry, that letter isn't in the word.")
|
print("Sorry, that letter isn't in the word.")
|
||||||
|
|
||||||
if guessWrong == 10:
|
if guess_wrong == 10:
|
||||||
print("Sorry, you lose. The word was " + guessTarget)
|
print("Sorry, you lose. The word was " + guess_target)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
@@ -194,14 +194,14 @@ def main():
|
|||||||
"""Main"""
|
"""Main"""
|
||||||
|
|
||||||
random.shuffle(words)
|
random.shuffle(words)
|
||||||
wordCurrent = 0
|
word_current = 0
|
||||||
wordCount = 49
|
word_count = 49
|
||||||
|
|
||||||
keep_playing = True
|
keep_playing = True
|
||||||
while keep_playing:
|
while keep_playing:
|
||||||
play_game(words[wordCurrent])
|
play_game(words[word_current])
|
||||||
wordCurrent = wordCurrent + 1
|
word_current = word_current + 1
|
||||||
if wordCurrent >= wordCount:
|
if word_current >= word_count:
|
||||||
print("You did all the words!!")
|
print("You did all the words!!")
|
||||||
keep_playing = False
|
keep_playing = False
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user