Python编程驾驶飞船游戏。

python新手小白,在学《Python编程从入门到实践》

编写‘驾驶飞船’游戏## 主程序 alien_invasion :

import sys
import pygame
import game_functions as gf
from settings import Settings
from ship import Ship
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width,ai_settings.screen_height))
    ship = Ship(screen)
    pygame.display.set_caption("Alien Invasion")
    while True:
        gf.check_events(ship)
        gf.update_screen(ai_settings,screen,ship)
        pygame.display.flip()
run_game()

调用的game_functions:

import sys
import pygame
def check_events(ship):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWM:
            if event.key == pygame.K_RIGHT:
                ship.rect.centerx += 1

def update_screen(ai_settings,screen,ship):
    screen.fill(ai_settings.bg_color)
    ship.blitme()

运行的时候,显示调用的函数有问题,错误代码: AttributeError module ‘pygame’ have no attribute ‘KEYDOWN’,翻来覆去不知道为啥,请路过的大神解答,指点迷津

1个回答

elif event.type == pygame.KEYDOWM:
改成KEYDOWN

qq_36568227
qq_36568227 谢谢! 这单词我还特意看过 感觉‘没拼错’,我怎么能这么粗心,,晕啊
5 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问