代码区:

import pygame.display
from pygame import *
#设置窗口大小
SCREEN_WIDTH = 700
SCREEN_HEIGHT = 500
# 设置颜色
BG_COLOR = pygame.Color(0,0,0)
# 主类
class MainGme():
    def __init__(self):
        pass
#       开始游戏
    def startGame(self):
        pass
#       加载化窗口
#       初始主窗口
        pygame.display.init()
        #设置窗口
        MainGme.window = pygame.display.set_mode([SCREEN_WIDTH,SCREEN_HEIGHT])
        #设置窗口标题
        pygame.display.set_caption("坦克大战初版")
        while True:
            #设置填充色
            MainGme.window.fill(BG_COLOR)
            #窗口一直显示
            pygame.display.update()
#       结束游戏
    def endGame(self):
        pass
# 我方坦克
# class Mytank(Tank):
#     def __init__(self):
#         pass
# # 敌方坦克
# class EnemyTank(Tank):
#     def __init__(self):
#         pass
# 子弹类
class Bullet():
    def __init__(self):
        pass
# 墙壁类
class Wall():
    def __init__(self):
        pass
# 爆炸效果
# 音效

运行结果:

pygame 2.0.1 (SDL 2.0.14, Python 3.9.6)
Hello from the pygame community. https://www.pygame.org/contribute.html


相关课程:Python 全系列>第二阶段:Python 深入与提高>游戏开发-坦克大战>加载主窗口

课程分类

百战程序员微信公众号

百战程序员微信小程序

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