Hangman pygame 游戏机制问题 [英] Hangman pygame game mechanic problems
问题描述
在我的游戏中出现的问题是,当我尝试在游戏中插入单词时,它不显示字母,正确时应该向我显示字母,如果错误应该惩罚我通过添加刽子手的一部分.
The problem occurs in my game is that when I'm trying to insert word into the game, it doesn't show the letter, it should be showing me the letter when it is correct, if its wrong it should penalize me by adding one part of the hangman.
我确实创建了惩罚函数和在正确时显示用户输入的字母的函数,请帮助!!
I did create the penalty function and the function that display the letter input by user when it is correct, help please !!
这是我的代码:http://pastebin.com/du98i88G
我认为 game()
函数可能有问题`
虽然不是游戏退出:对于 pygame.event.get() 中的事件:如果 event.type == pygame.QUIT:pygame.quit()退出()
I think there might be problem in the game()
function
`
while not gameQuit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if guess in secret:
correct_letters = correct_letters + guess
found = True
for i in range(len(secret)):
if secret[i] not in correct_letters:
found = False
break
if found == True:
screen.fill(black)
msgSize = pygame.font.Font("Hangman/ITCBLKAD.TTF", 80)
msgText, msgText_Size = text_objects('Congratz!! You won!', msgSize)
msgText_Size.center = ((display_width/2),(display_height/2)-70)
screen.blit(msgText, msgText_Size)
msgSize1 = pygame.font.Font("Hangman/ITCBLKAD.TTF", 50)
msgText1, msgText1_Size = text_objects('Play again?', msgSize1)
msgText1_Size.center = ((display_width/2),(display_height/2)+30)
screen.blit(msgText1, msgText1_Size)
buttonYes("Yes",350,295,80,40,black,grey)
buttonNo("No",550,295,80,40,black,grey)
pygame.display.flip()
else:
incorrect_letters = incorrect_letters + guess
if len(incorrect_letters) == 7:
screen.fill(black)
display(incorrect_letters,correct_letters,secret)
msgSize = pygame.font.Font("Hangman/ITCBLKAD.TTF", 80)
msgText, msgText_Size = text_objects('You Lose! the word was: ' + secret, msgSize)
msgText_Size.center = ((display_width/2),(display_height/2)-70)
screen.blit(msgText, msgText_Size)
msgSize1 = pygame.font.Font("Hangman/ITCBLKAD.TTF", 50)
msgText1, msgText1_Size = text_objects('Play again?', msgSize1)
msgText1_Size.center = ((display_width/2),(display_height/2)+30)
screen.blit(msgText1, msgText1_Size)
buttonYes("Yes",350,295,80,40,black,grey)
buttonNo("No",550,295,80,40,black,grey)
pygame.display.flip()
`
推荐答案
您没有在猜测错误后更新您的显示.尝试移动线
You are not updating your display after a wrong guess. Try moving the line
display(incorrect_letters,correct_letters,secret)
在 if
块之上.
使用变量 found
可能会出现另一个问题.您检查 if guess in secret
并在下一个块中检查 found
的值,该值仅在前一个 if
块中定义.在第一个 if
块上方添加 found = False
以防止这种情况发生.
Another problem might arise from the use of the variable found
. You check if guess in secret
and in the next block you check the value of found
which is defined only within the previous if
block. Add found = False
above the first if
block to prevent that.
这篇关于Hangman pygame 游戏机制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!