刽子手pygame游戏机制问题

时间:2016-11-06 12:05:00

标签: python pygame

我的游戏中出现的问题是,当我试图在游戏中插入单词时,它没有显示该字母,它应该在正确时显示该字母,如果错误它应该通过添加刽子手的一部分来惩罚我。

我确实创建了惩罚函数和用户在正确时显示输入字母的功能,请帮忙!!

这是我的代码:http://pastebin.com/du98i88G

我认为game()功能可能存在问题 `
    而不是gameQuit:         对于pygame.event.get()中的事件:             if 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()

`

1 个答案:

答案 0 :(得分:0)

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

display(incorrect_letters,correct_letters,secret)

if区块之上。

使用变量found可能会产生另一个问题。您检查if guess in secret,然后在下一个块中检查found的值,该值仅在上一个if块中定义。在第一个found = False块上方添加if以防止此情况发生。