老师,你好,视频中这个调用是如何实现的呀,move方法不是Tank类中的吗
你好:老师
就是现在图片在本地磁盘D中,我想把他整到pycharm中去。以gif格式,就是如何将扑克牌图片导入
老师,请问一下,没有这个模块是什么意思,我该怎样去导入呢
老师请问一下 我这个编码是“encoding=“utf-8”,为啥还说是”gbk“的问题呐 ,改了还几次 不清楚怎么操作了,麻烦老师帮忙看一下 。
Entry(self).grid(row=0, column=0, columnspan=5, pady=10, rowspan=2)
输入框可以通过columnspan调整占用多少列,但为什么不能用rowspan调整占用多少行?如果我想调整输入框占用2行的宽度,应该如何设置?
import os allfiles = [] def getAllFiles(path,level): childFiles = os.listdir(path) for file in childFiles: filepath = os.path.join(path,file) if os.path.isdir(filepath): getAllFiles(filepath,level+1) allfiles.append('\t'* level + filepath) getAllFiles('movie',0) for f in reversed(allfiles): print(f)
老师,这些代码我实在是理解不了,能给详细解释一下吗?level起到什么作用?listdir又起到什么作用?path表示的是什么?
老师,wall不是继承了精灵类,也可以使用sprite的方法吗
为什么用self不显示图片,什么时候用root和self
老师,我这两个代码是一样的,可是创造的窗口为什么不同?
图1是代码,图2是lian_xi的运行图,图3是ji_suan_qi的运行图
pygametimerandom _display = pygame.display COLOR_BLACK = pygame.Color() COLOR_RED = pygame.Color() version = MainGame(): window = SCREEN_HEIGHT = SCREEN_WIDTH = TANK_P1 = EnemyTank_list = [] EnemTank_count = Bullet_list = [] Enemy_bullet_list = [] (): (): _display.init() MainGame.window = _display.set_mode([MainGame.SCREEN_WIDTHMainGame.SCREEN_HEIGHT]) MainGame.TANK_P1 = Tank() .creatEnemyTank() _display.set_caption(+version) : MainGame.window.fill(COLOR_BLACK) .getEvent() MainGame.window.blit(.getTextSurface(%(MainGame.EnemyTank_list))()) MainGame.TANK_P1.displayTank() .blitEnemyTank() MainGame.TANK_P1 MainGame.TANK_P1.stop: MainGame.TANK_P1.move() .blitBullet() .blitEnemyBullet() time.sleep() _display.update() (): top = speed = random.randint() i (MainGame.EnemTank_count): left = random.randint() eTank = EnemyTank(left*topspeed) MainGame.EnemyTank_list.append(eTank) (): eTank MainGame.EnemyTank_list: eTank.displayTank() eTank.randMove() eBullet = eTank.shot() MainGame.Enemy_bullet_list.append(eBullet) (): bullet MainGame.Bullet_list: bullet.live: bullet.displayBullet() bullet.bulletMove() : MainGame.Bullet_list.remove(bullet) (): eBullet MainGame.Enemy_bullet_list: eBullet.live: eBullet.displayBullet() eBullet.bulletMove() : MainGame.Bullet_list.remove(eBullet) (): 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: () (MainGame.Bullet_list) < : m = Bullet(MainGame.TANK_P1) MainGame.Bullet_list.append(m) : () (%(MainGame.Bullet_list)) 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 = (text): pygame.font.init() font = pygame.font.SysFont() textSurface = font.render(textCOLOR_RED) textSurface (): () () Tank(): (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 = .stop = (): .direction == : .rect.left > : .rect.left -= .speed .direction == : .rect.left + .rect.height < MainGame.SCREEN_WIDTH: .rect.left += .speed .direction == : .rect.top > : .rect.top -= .speed .direction == : .rect.top + .rect.height < MainGame.SCREEN_HEIGHT: .rect.top += .speed (): Bullet() (): .image = .images[.direction] MainGame.window.blit(.image.rect) MyTank(Tank): (): EnemyTank(Tank): (lefttopspeed): .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 -= Bullet(): (tank): .image = pygame.image.load() .direction = tank.direction .rect = .image.get_rect() .direction == : .rect.left = tank.rect.left + tank.rect.width/- .rect.width/.rect.top = tank.rect.top - .rect.height .direction == : .rect.left = tank.rect.left + tank.rect.width / - .rect.width / .rect.top = tank.rect.top + tank.rect.height .direction == : .rect.left = tank.rect.left - .rect.width / - .rect.width / .rect.top = tank.rect.top + tank.rect.width / - .rect.width / .direction == : .rect.left = tank.rect.left + tank.rect.width .rect.top = tank.rect.top + tank.rect.width / - .rect.width / .speed = .live = (): .direction == : .rect.top > : .rect.top -= .speed : .live = .direction == : .rect.top < MainGame.SCREEN_HEIGHT - .rect.height: .rect.top += .speed : .live = .direction == : .rect.left > : .rect.left -= .speed : .live = .direction == : .rect.left < MainGame.SCREEN_WIDTH - .rect.width: .rect.left += .speed : .live = (): MainGame.window.blit(.image.rect) Explode(): (): (): Wall(): (): (): Music(): (): (): MainGame().startGame()
检查了好几次,每次到了8分38秒此时效果时候就弹出下面的提示,该怎么处理呢?
老师这里stu不是继承了as了吗???那为什么不能直接输出as里定义的私有属性name,
就是print调用私有属性name 那里最后一行,stu不行,as就可以??????
老师,安装虚拟环境的目的是什么
import pygame # 设置通用属性 BG_COLOR = pygame.Color(255,255,255) SCREEN_WIDTH = 700 SCREEN_HEIGHT = 500 TEXT_COLOR = pygame.Color(255,0,0) class Tank(): def __init__(self): pass #坦克的移动方法 def move(self): pass #碰撞墙壁的方法 def hitWalls(self): pass #射击方法 def shot(self): pass #展示坦克 def displayTank(self): pass class MyTank(Tank): def __init__(self): pass #碰撞敌方坦克的方法 def hitEnemyTank(self): pass class EnemyTank(Tank): ''' 敌方坦克类 ''' def __init__(self) -> None: pass class Bullet: ''' 子弹类 ''' def __init__(self) -> None: pass def display_bullet(self) -> None: ''' 显示子弹 ''' pass def move(self) -> None: ''' 子弹的移动 ''' pass class Wall: ''' 墙壁类 ''' def __init__(self) -> None: pass def display_wall(self) -> None: ''' 显示墙壁 ''' pass class Explode: ''' 爆炸效果类 ''' def __init__(self) -> None: pass def display_explode(self) -> None: ''' 显示爆炸效果 ''' pass class Music: ''' 音效类 ''' def __init__(self) -> None: pass def play_music(self) -> None: ''' 播放音效 ''' pass class MainGame: ''' 游戏主窗口类 ''' def __init__(self) -> None: pass def start_game(self) -> None: ''' 开始游戏 ''' # 初始化游戏窗口 pygame.display.init() # 创建一个窗口 MainGame.window = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) # 设置窗口标题 pygame.display.set_caption('坦克大战1.0') # 刷新窗口 while True: # 给窗口设置填充色 MainGame.window.fill(BG_COLOR) num = 6 text = self.get_surface(f'敌方坦克剩余数量{num}') def get_text_surface(self,text:str) -> None: ''' 获取文字的图片 ''' # 初始化字体模块 pygame.font.init() # 获取可以使用的字体 # print(pygame.font.get_fonts()) # 创建字体 font = pygame.font.SysFont('kaiti',18) # 绘制文字信息 text_surface = font.render(text,True,TEXT_COLOR) # 将绘制的文字信息返回 return text_surface # 1.要增加文字内容 # 2.如何把文字加上 MainGame.window.blit(text,(10,10)) pygame.display.update() def end_game(self) -> None: ''' 结束游戏 ''' pass
函数为啥用不了,老师
我问一下
什么情况下会需要重新加载模块。。。。。。
btn01 = Button(root)
这参数是root 我看源码,root就是master这个参数吗?表示Button这个组件是 属于root的意思吧
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637