会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132450个问题
JAVA 全系列/第十二阶段:Spring Cloud Alibaba技术栈/Dubbo 4591楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于SpringSecurity实现后台登录功能 4593楼
JAVA 全系列/(旧的隐藏)第二十一阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 4596楼
Python 全系列/第一阶段:Python入门/面向对象 4597楼

9F879510-E04C-4537-AF64-ACBDA3A127B9.jpeg

JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 4598楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/项目环境准备 4599楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 4600楼
JAVA 全系列/第十八阶段:亿级高并发电商项目/亿级高并发电商项目(旧) 4601楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/数据结构 4602楼

pygame,time
random
_display=pygame.display
COLOR_BLACK=pygame.Color(,,)
COLOR_RED=pygame.Color(,,)
():
    window=TANK_P1=SCREEN_HEIGHT=SCREEN_WIDTH=EnemyTank_list=[]
    EnemyTank_count=():
        ():
        _display.init()
        MainGame.window=_display.set_mode([MainGame.SCREEN_WIDTH,MainGame.SCREEN_HEIGHT])
        MainGame.TANK_P1 = Tank(, )
        .createEnemyTank()
        _display.set_caption()

        :
            time.sleep()
            MainGame.window.fill(COLOR_BLACK)
            .getEvent()
            MainGame.window.blit(.getTextface(%),(,))

            MainGame.TANK_P1.displayTank()

            .displayEnemyTank()
            MainGame.TANK_P1.stop == :
                MainGame.TANK_P1.move()
            _display.update()


    ():
        top = i (MainGame.EnemyTank_count):
            left = random.randint(, )
            speed = random.randint(, )
            eTank = EnemyTank(left, top, speed)
            MainGame.EnemyTank_list.append(eTank)


   ():
        eTank MainGame.EnemyTank_list:
            eTank.displayTank()
            eTank.randMove()

    ():
        ()
        ()

    (,text):
        pygame.font.init()
        font=pygame.font.SysFont(,)
        textSurface=font.render(text,,COLOR_RED)
        textSurface

():
        eventList=pygame.event.get()
        event eventList:
    event.type==pygame.QUIT:
                .endGame()
    event.type==pygame.KEYDOWN:
     event.key==pygame.K_LEFT:
                    ()
                    MainGame.TANK_P1.direction=MainGame.TANK_P1.stop=event.key==pygame.K_RIGHT:
                    ()
                    MainGame.TANK_P1.direction=MainGame.TANK_P1.stop=event.key == pygame.K_UP:
                        ()
                        MainGame.TANK_P1.direction = MainGame.TANK_P1.stop = event.key == pygame.K_DOWN:
                            ()
                            MainGame.TANK_P1.direction = MainGame.TANK_P1.stop = event.key==pygame.K_SPACE:
                    ()


             event.type==pygame.KEYUP:
                    event.key==pygame.K_LEFT event.key==pygame.K_RIGHT \
                        event.key == pygame.K_UP event.key==pygame.K_DOWN:
                     MainGame.TANK_P1.stop=():
    (,left,top):
        .images={
            :pygame.image.load(),
            : pygame.image.load(),
            : pygame.image.load(),
            : pygame.image.load()
        }

        .direction=.image=.images[.direction]
        .rect=.image.get_rect()
        .rect.left=left
        .rect.top=top
        .stop = .speed=():
        .image=.images[.direction]
        MainGame.window.blit(.image,.rect)


():
        .direction==:
            .rect.left>:
                .rect.left-=.speed
        .direction==:
            .rect.left+.rect.width<MainGame.SCREEN_WIDTH:
                .rect.left+=.speed
        .direction==:
            .rect.top > :
                 .rect.top-=.speed
        .direction==:
            .rect.top + .rect.height< MainGame.SCREEN_HEIGHT:
                .rect.top += .speed

    ():
        ():
        ():
        (Tank):
    ():
        ():
        (Tank):

    (,left,top,speed):
        .images={
            :pygame.image.load(),
            :pygame.image.load(),
            :pygame.image.load(),
            :pygame.image.load()
        }
        .direction=.randDirection()
        .image=.images[.direction]
        .rect=.image.get_rect()
        .rect.left=left
        .rect.top=top
        .speed=speed
        .stop=.step=():
            num=random.randint(,)
            num==:
                 num == :
                num == :
                num == :
                ():
        .step<=:
            .direction=.randDirection()
            .step=:
            .move()
            .step-=():
        ():
    ():
        ():
        ():
        ():
        ():
        ():
        ():
    ():
        ():
        ():
    ():
        ():
        ():
    ():
        ():
        __name__==:
    MainGame().startGame()



报错

"C:\Program Files (x86)\Python36-32\python.exe" C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py

pygame 2.0.1 (SDL 2.0.14, Python 3.6.5)

Hello from the pygame community. https://www.pygame.org/contribute.html

Traceback (most recent call last):

  File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 284, in <module>

    MainGame().startGame()

  File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 28, in startGame

    self.createEnemyTank()

  File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 59, in createEnemyTank

    eTank = EnemyTank(left, top, speed)

  File "C:/Users/Administrator/Desktop/python课件/坦克游戏/代码/test/tank08.py", line 208, in __init__

    self.image=self.images[self.direction]

KeyError: None


Process finished with exit code 1



老师,帮我看看是什么原因


Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 4603楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 4604楼
Python 全系列/第五阶段:数据库编程/mysql的使用 4605楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637