pycharm为什么无法识别某些键命令?

时间:2019-06-26 16:06:55

标签: python pycharm

大约一年前,我能够运行一个使用pygame的程序。我的程序可以运行,但是无法识别某些键盘命令。例如,当我输入“ A”或“ S”时,游戏状态应更改,但不会更改。更具体地说,for循环中的第二个外部if块不应该运行,而应该运行。

首先,我确保将pygame作为模块安装到pycharm上。对于粘贴的代码部分,我也进入了调试模式,但我仍然很难找出问题所在,以及为什么它会跳过for循环中的第二个外部if块。

if __name__ == '__main__':
start_game()
update_game()

while True:
    pygame.time.wait(GAME_SPEED)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit(0)
        if event.type == pygame.KEYDOWN and not a1_game.GAME_IS_OVER:
            # If the current player is using a manual playstyle, the
            # pick a move when a key is pressed
            if (not a1_game.BATTLE_QUEUE.is_over() and
                    a1_game.BATTLE_QUEUE.peek().playstyle.is_manual):
                k = 'X'
                if event.key == pygame.K_a:
                    k = 'A'
                elif event.key == pygame.K_s:
                    k = 'S'

                a1_game.LAST_KEY_PRESSED = k
                a1_game.perform_attack()

    # If the current player isn't using a manual playstyle, pick a move
    if (not a1_game.GAME_IS_OVER and
        not a1_game.BATTLE_QUEUE.is_over() and
        not a1_game.BATTLE_QUEUE.peek().playstyle.is_manual and
            RANDOM_TIMER == 10):
        a1_game.perform_attack()

    # Redraw the game
    update_game()

    # Only let the random strategy make a decision every 10 ticks of time
    RANDOM_TIMER -= 1
    if RANDOM_TIMER == 0:
        RANDOM_TIMER = 10

pygame.quit()
sys.exit(0)

0 个答案:

没有答案