2016-11-06 97 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:看看更新後的答案,如果不是試着將你的例子修剪成一個最小的工作例子,即沒有本地圖像和字體。 –