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

import pygame
COLOR_BLUE=pygame.Color(0,0,0)
COLOR_red=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([700,600])
       pygame.display.set_caption("坦克大战")
       while True:
         MainGame.window.fill(COLOR_BLUE)
         self.eventlist()
         pygame.display.update()
         MainGame.window.blit(self.getTextSurface("剩余敌方坦克数量%d"%6),(5,5))
#结束游戏
    def endGame(self):
        print("谢谢使用,欢迎下次使用")
        exit()
    def eventlist(self):
        enentlist=pygame.event.get()
        for event in enentlist:
            if event.type==pygame.QUIT:
                self.endGame()
            if event.type==pygame.KEYDOWN:
                if event.key==pygame.K_UP:
                    print("按下上键,坦克向上移动")
                if event.key == pygame.K_DOWN:
                    print("按下下键,坦克向下移动")
                if event.key == pygame.K_LEFT:
                    print("按下左键,坦克向左移动")
                if event.key == pygame.K_RIGHT:
                    print("按下右键,坦克向右移动")
    def getTextSurface(self,text):
        pygame.font.init()
        font=pygame.font.SysFont("kaiti",18)
        testSurface=font.render(text,True,COLOR_red)
        return testSurface
MainGame().startGame()
class Tank():
    def __init__(self):

39.png


这要怎么解决

Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 7楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 8楼
Python 全系列/第二阶段:Python 深入与提高/模块 9楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 11楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 12楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 14楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 15楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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