2016-11-06 94 views
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() 

`

回答

0

错误的猜测后,您没有更新您的显示器。尝试移动线

display(incorrect_letters,correct_letters,secret) 

高于if块。


使用变量found可能会导致另一个问题。您检查if guess in secret并在下一个块中检查仅在之前的if块中定义的found的值。在第一个if块之上添加found = False以防止出现这种情况。

+0

我试过了@Maximillian Peters,不是很伤心 – DarkxRift

+0

@DarkxRift:看看更新后的答案,如果不是试着将你的例子修剪成一个最小的工作例子,即没有本地图像和字体。 –