保持在挂人蟒蛇猜的字母的进展

时间:2015-04-15 02:34:30

标签: python user-interface

Graphics=['''
------------
|         |''','''


------------
|         |         
|          O''','''


------------
|         | 
|          O 
|         / ''','''

------------
|         | 
|          O 
|         / |''','''


------------
|         | 
|          O 
|         / | 
|          | ''','''


------------
|         |
|          O 
|         / |
|          |
|         /  
|
|            ''','''


------------
|         |
|          O 
|         / |
|          |
|         / | 
|
|            ''']



import random

class Hangman():

    def Playing(self):
        listOfWords = ["example", "says", "python", "rocks"]

        again = True
        while again:

            guessWord = random.choice(listOfWords)
            board = "*" * len(guessWord)
            alreadySaid = set()
            mistakes = 7

            print(" ".join(board))

            guessed = False

这些是我想要跟踪的猜测

            while not guessed and mistakes > 0:

                whatplayersaid = input("Guess a letter: ")

                if whatplayersaid in guessWord:
                    alreadySaid.add(whatplayersaid)
                    board = "".join([char if char in alreadySaid else "_" for char in guessWord])
                    if board == guessWord:
                        guessed = True
                else:
                    mistakes -= 1
                    print("Nope.", mistakes, "mistakes left.")
                    print("Letters Guessed:",guessed)

这是我的错误所在。

                    print(Graphics[6-mistakes])






                print(" ".join(board))

            again = (input("Again [y/n]: ").lower() == 'y')

Hangman().Playing()
  

我希望保持猜测字母的进度,并在每次猜测时打印出来。我该怎么做?,我现在只返回最后一次不正确的猜测

1 个答案:

答案 0 :(得分:1)

您需要做的是不打印print(Graph)这会打印Graph数组的位置。您需要打印如下内容:

print(Graph[7-mistakes])