会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 128778个问题
Python 全系列/第二阶段:Python 深入与提高/坦克大战 106楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 107楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 108楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 110楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 111楼

pygame


_display = pygame.display
color_black = pygame.Color()
color_red = pygame.Color()
version = maingame():
    window = Screen_width = Screen_height = TANK_P1 = ():
        _display.init()
        maingame.window = _display.set_mode([maingame.Screen_widthmaingame.Screen_height])
        maingame.TANK_P1 = Tank()
        _display.set_caption(+ version)
        .getTextSurface()
        :
            maingame.window.fill(color_black)
            .getEvent()
            maingame.window.blit(.getTextSurface(% )())
            maingame.TANK_P1.displayTank()
            maingame.TANK_P1.move()
            _display.update()

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

    (text=):
        pygame.font.init()
        = pygame.font.get_fonts()
        font = pygame.font.SysFont()
        textSurface = font.render(textcolor_red)
        textSurface
        (fontList)

    ():
        ()
        ()


Tank:
    TANK_P1 = (lefttop):
        .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

        .speed = ():
        .image = .images[.direction]
        maingame.window.blit(.image.rect)

    ():

        .direction == :
            .rect.left > :
                .rect.left -= .speed
        .direction == :
            .rect.top > :
                .rect.top -= .speed
        .direction == :
            .rect.top + .rect.height < maingame.Screen_width:
                .rect.top += .speed
            .direction == :
                .rect.left + .rect.height < maingame.Screen_height:
                    .rect.left += .speed

    ():

为什么边界这卡不住 老师!?

Python 全系列/第二阶段:Python 深入与提高/坦克大战 112楼

pygame


_display = pygame.display
color_black = pygame.Color()
color_red = pygame.Color()
version = maingame():
    window = Screen_width = Screen_height = TANK_P1 = ():
        _display.init()
        maingame.window = _display.set_mode([maingame.Screen_widthmaingame.Screen_height])
        maingame.TANK_P1 = Tank()
        _display.set_caption(+ version)
        .getTextSurface()
        :
            maingame.window.fill(color_black)
            .getEvent()
            maingame.window.blit(.getTextSurface(% )())
            maingame.TANK_P1.displayTank()
            maingame.TANK_P1.move()
            _display.update()

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

    (text=):
        pygame.font.init()
        = pygame.font.get_fonts()
        font = pygame.font.SysFont()
        textSurface = font.render(textcolor_red)
        textSurface
        (fontList)

    ():
        ()
        ()


Tank:
    TANK_P1 = (lefttop):
        .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

        .speed = ():
        .image = .images[.direction]
        maingame.window.blit(.image.rect)

    ():

        .direction == :
            .rect.left > :
                .rect.left -= .speed
        .direction == :
            .rect.top > :
                .rect.top -= .speed
        .direction == :
            .rect.top + .rect.height < maingame.Screen_width:
                .rect.top += .speed
            .direction == :
                .rect.left + .rect.height < maingame.Screen_height:
                    .rect.left += .speed

    ():

为什么边界这卡不住 老师!?

Python 全系列/第二阶段:Python 深入与提高/坦克大战 113楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 114楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 115楼
Python 全系列/第二阶段:Python 深入与提高/模块 116楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 117楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 118楼
Python 全系列/第二阶段:Python 深入与提高/坦克大战 120楼

百战程序员微信公众号

百战程序员微信小程序

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