0
在我的游戏中发生的问题是,当我试图插入游戏中的单词时,它不显示该字母,它应该向我显示该字母是正确的,如果它错误的,它应该通过增加hang子手的一部分来惩罚我。Hang子棋pygame游戏机制问题
我确实创建了惩罚函数和显示用户输入的字母正确的函数,请帮助!
这是我的代码:http://pastebin.com/du98i88G
我觉得可能在game()
功能 `
而不是gameQuit是问题: 在pygame.event.get事件(): 如果event.type = = pygame.QUIT: pygame.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()
`
我试过了@Maximillian Peters,不是很伤心 – DarkxRift
@DarkxRift:看看更新后的答案,如果不是试着将你的例子修剪成一个最小的工作例子,即没有本地图像和字体。 –