我在Python 3.5.1中創建一個hang子手遊戲,除了涉及猜測部分時,一切都進展順利。當信件被正確猜測時,我會打印「華友世界」,當它沒有被正確猜測時,我會畫出額外的身體部位。我的問題是,即使一個字母被正確地猜測它還將利用其它身體部位:Hang子手繪製無論正確的字母(Python,烏龜)
import drawHangman
import turtle
import random
def main():
window = turtle.Screen()
window.setup(400, 400, 200, 200)
HG = turtle.Turtle()
drawHangman.default(HG)
wrongGuess = 0
maxGuesses = 0
lines = open('wordlist.txt').read().splitlines()
myline =random.choice(lines)
print(myline)
name = input("Welcome to hangman! What is your name? \n")
print("Welcome", name + "! \n The rules are as follows: \n 1) No looking at answer list! \n 2) Do not have fun!! \n 3) No hacking my game!")
tos = input("Do you accept the rules provided above? Type Yes or No. \n")
if tos == "no":
print("Who cares! The rules suck anyways!")
elif tos == "yes":
print("HI")
else:
print("You don't listen very well. I guess proceed ugh")
while maxGuesses < 6:
guess = input("Please input your guess!")
maxGuesses += 1
for char in myline:
if char in guess:
print("Hurray")
else:
wrongGuess += 1
print("You have", 6 - maxGuesses, "guesses left!")
if wrongGuess == 1:
drawHangman.drawHead(HG)
elif wrongGuess == 2:
drawHangman.drawBody(HG)
elif wrongGuess == 3:
drawHangman.drawLeftArm(HG)
elif wrongGuess == 4:
drawHangman.drawRightArm(HG)
elif wrongGuess == 5:
drawHangman.drawLeftLeg(HG)
elif wrongGuess == 6:
drawHangman.drawRightLeg(HG)
else:
playAgain = input('Do you want to play again? (yes or no)')
if playAgain == "yes":
drawHangman.reset(HG)
main()
else:
print("Thanks for playing!")
return
main()
我知道它是與別的地方告訴它有一種錯誤的信,但我不能部分想辦法。我試着縮進一個空格,但這只是打印剩下的猜測量。任何幫助表示讚賞。
PS。 drawHangman.*
例程來自我在我的src文件夾中包含正文部分的文件。
http://i.imgur.com/7uTKA1b.png HTTP://i.imgur .com/TGdiX3I.png 我嘗試過,但我得到奇怪的結果。 –
我無法將第二個屏幕截圖中的輸出完全匹配到源代碼窗格中顯示的代碼部分。你的程序確實有更多問題。例如,爲什麼你要迭代用戶輸入中的所有字符?不僅應該看第一個字符嗎?每個輸入將至少有一個換行符,與您的測試字中的任何字母都不匹配。我還不清楚這條消息會如何打印三次。 –