会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题

import pygame
screen_width = 700
screen_height = 400
BG_color = pygame.Color(0, 0, 0)
Text_COLOR = pygame.Color(255, 0, 0)

class MainGame():
    window = None

    def __init__(self):
        pass

    def startGame(self):
        # 初始化显示模块
        pygame.display.init()
        # 初始化显示窗口
        MainGame.window = pygame.display.set_mode([screen_width, screen_height])
        pygame.display.set_caption("坦克大战1.0")
        while True:
            # 给窗口设置填充色
            self.getEvent()
            MainGame.window.blit(self.getTextSurface('剩余敌方坦克数量%d'%6), (10, 10))
            MainGame.window.fill(BG_color)
            pygame.display.update()

    def endGame(self):
        pass

    def getTextSurface(self, text):
# 初始化字体模块
        pygame.font.init()
        # 获取字体font对象
        pygame.font.get_fonts()

        s= pygame.font.SysFont("kaiti", 18)
        #绘制文本信息
        textSurface = s.render(text, True, Text_COLOR)
        return textSurface

    def getEvent(self):
        #获取所有事件
        eventList = pygame.event.get()
        #遍历事件
        for event in eventList:
# 判断按下的
            if event.type == pygame.QUIT:
                exit()



class Tank():
    def __init__(self):
        pass

    def move(self):
        pass

    def shot(self):
        pass

    def display(self):
        pass


# 我方坦克
class MyTank(Tank):
    def __init__(self):
        pass


class EnmeyTank(Tank):
    def __init__(self):
        pass


class Bullet():
    def __init__(self):
        pass

    def move(self):
        pass

    def displayBullet(self):
        pass


class Wall():
    def __init__(self):
        pass

    def displayWall(self):
        pass


class Explode():
    def __init__(self):
        pass

    def displayExplode(self):
        pass


class Music():
    def __init__(self):
        pass

    def playMusic(self):
        pass


if __name__ == "__main__":
    MainGame().startGame()

image.png老师我这段代码没有报错,但是左上角却没有文本信息的显示,新surface没出来啊,帮忙看看,谢谢

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 2581楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 2591楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 2592楼

images.rar

老师,这个练习里,在166行,那个移动方法里,我只能实现一个周期的移动,就这一个周期我添加了五种属性(应该是每次当step减到0的时候让他复位,但是我没法实现),还有就是怎么添加一个循环,让他继续往下运动

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 2593楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 2594楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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