qq_36568227 2019-08-15 17:28 采纳率: 0%
浏览 1479

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条回答

  • liang_shui_guo 2019-08-15 17:46
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退