这个加的w是什么意思呐
自己解决了
老师,我是按照视频一步一步敲的,为什么报错了?
显示是版本问题,然后我这样升级了一下,显示安装的路径是C盘,难道是需要创建的项目在这个路径吗c:\program files\python36\lib\site-packages (19.3.1)
按装不了啊,尝试了python -m pip install --upgrade pip更新之后继续输入pip install pygame 就会这样
问题: 怎么总是提示我输入的三对双引号有问题呢? 这个输入有什么诀窍吗? 不就是Enter 键旁边的引号键 分别按三次吗? 为什么原始代码里面的正确的, 自己的总是提示错误呢?
pygametimerandom pygame.sprite Sprite SCREEN_WIDTH = SCREEN_HEIGHT = BG_COLOR = pygame.Color() TEXT_COLOR = pygame.Color() BaseItem(Sprite): (): pygame.sprite.Sprite.() MainGame(): window = my_tank = enemyTankList = [] enemyTankCount = myBulletList = [] enemyBulletList = [] explodeList = [] (): (): pygame.display.init() MainGame.window = pygame.display.set_mode([SCREEN_WIDTHSCREEN_HEIGHT]) MainGame.my_tank = Tank() .createEnemyTank() pygame.display.set_caption() : time.sleep() MainGame.window.fill(BG_COLOR) .getEvent() MainGame.window.blit(.getTextSuface(% (MainGame.enemyTankList))()) MainGame.my_tank MainGame.my_tank.live: MainGame.my_tank.displayTank() : MainGame.my_tank MainGame.my_tank = .blitEnemyTank() .blitMyBullet() .blitEnemyBullet() .blitExplode() MainGame.my_tank MainGame.my_tank.live: MainGame.my_tank.stop: MainGame.my_tank.move() pygame.display.update() (): top = i (MainGame.enemyTankCount): left = random.randint() speed = random.randint() enemy = EnemyTank(lefttopspeed) MainGame.enemyTankList.append(enemy) (): enemyTank MainGame.enemyTankList: enemyTank.live: enemyTank.displayTank() enemyTank.randMove() enemyBullet = enemyTank.shot() enemyBullet: MainGame.enemyBulletList.append(enemyBullet) : MainGame.enemyTankList.remove(enemyTank) (): myBullet MainGame.myBulletList: myBullet.live: myBullet.displayBullet() myBullet.move() myBullet.myBullet_hit_enemyTank() : MainGame.myBulletList.remove(myBullet) (): enemyBullet MainGame.enemyBulletList: enemyBullet.live: enemyBullet.displayBullet() enemyBullet.move() enemyBullet.enemyBullet_hit_myTank() : MainGame.enemyBulletList.remove(enemyBullet) (): explode MainGame.explodeList: explode.live: explode.displayExplode() : MainGame.explodeList.remove(explode) (): () () (text): pygame.font.init() font = pygame.font.SysFont() textSuface = font.render(textTEXT_COLOR) textSuface (): eventList = pygame.event.get() event eventList: event.type == pygame.QUIT: .endGame() event.type == pygame.KEYDOWN: MainGame.my_tank MainGame.my_tank.live: event.key == pygame.K_LEFT: MainGame.my_tank.direction = MainGame.my_tank.stop = () event.key == pygame.K_RIGHT: MainGame.my_tank.direction = MainGame.my_tank.stop = () event.key == pygame.K_UP: MainGame.my_tank.direction = MainGame.my_tank.stop = () event.key == pygame.K_DOWN: MainGame.my_tank.direction = MainGame.my_tank.stop = () event.key == pygame.K_SPACE: () (MainGame.myBulletList) < : myBullet = Bullet(MainGame.my_tank) MainGame.myBulletList.append(myBullet) event.type == pygame.KEYUP: event.key == pygame.K_UP event.key == pygame.K_DOWN event.key == pygame.K_RIGHT event.key == pygame.K_LEFT: MainGame.my_tank MainGame.my_tank.live: MainGame.my_tank.stop = Tank(Sprite): (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 = .live = (): .direction == : .rect.left > : .rect.left -= .speed .direction == : .rect.left + .rect.height < SCREEN_WIDTH: .rect.left += .speed .direction == : .rect.top > : .rect.top -= .speed .direction == : .rect.top + .rect.height < SCREEN_HEIGHT: .rect.top += .speed (): Bullet() (): .image = .images[.direction] MainGame.window.blit(.image.rect) MyTank(Tank): (): EnemyTank(Tank): (lefttopspeed): (EnemyTank).(lefttop) .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 .flag = .step = (): num = random.randint() num == : num == : num == : num == : (): .step <= : .direction = .randDirection() .step = : .move() .step -= (): num = random.randint() num < : Bullet() Bullet(Sprite): (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.height .rect.top = Tank.rect.top + Tank.rect.width / - .rect.height / .direction == : .rect.left = Tank.rect.left + Tank.rect.height .rect.top = Tank.rect.top + Tank.rect.height / - .rect.height / .speed = .live = (): .direction == : .rect.top > : .rect.top -= .speed : .live = .direction == : .rect.top + .rect.height < SCREEN_HEIGHT: .rect.top += .speed : .live = .direction == : .rect.left > : .rect.left -= .speed : .live = .direction == : .rect.left + .rect.width < SCREEN_WIDTH: .rect.left += .speed : .live = (): MainGame.window.blit(.image.rect) (): enemyTank MainGame.enemyTankList: pygame.sprite.collide_rect(enemyTank): enemyTank.live = .live = explode = Explode(enemyTank) MainGame.explodeList.append(explode) (): MainGame.my_tank MainGame.my_tank.live: pygame.sprite.collide_rect(MainGame.my_tank): explode = Explode(MainGame.my_tank) MainGame.explodeList.append(explode) .live = MainGame.my_tank.live = Wall(): (): (): Explode(): (tank): .rect = tank.rect .images = [ pygame.image.load()pygame.image.load()pygame.image.load()pygame.image.load()pygame.image.load()] .step = .image = .images[.step] .live = (): .step < (.images): .image = .images[.step] .step += MainGame.window.blit(.image.rect) : .live = .step = Music(): (): (): __name__ == : MainGame().startGame()
老师 为啥我写完后敌方子弹碰到我方坦克后整个画面就卡住不动了呢,也不报错
tkinter * tkinter messagebox root= Tk() btn01 = Button(root) btn01[]=btn01.pack() songhua(): messagebox.showinfo(,) () btn01.bind(,songhua) root.mainloop()
老师为什么 我的a1和b2 id是一样的呀
#coding=utf-8 ''' 新增功能 左上角文字绘制 左上角输出坦克数量 ''' import pygame SCREEN_WIDTH = 700 SCREEN_HEIGHT = 500 BG_COLOR = pygame.Color(0, 0, 0) TEXT_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.03') while True: MainGame.window.fill(BG_COLOR) #获取事件 self.getEvent() #绘制文字 MainGame.window.blit(self.getTextSurface('敌方坦克剩余数量%d' % 6), (10, 10)) pygame.display.update() # 结束游戏 def endGame(self): print('谢谢使用') exit() #左上角文字绘制 def getTextSurface(self, text): #初始化字体模块 pygame.font.init() #查看所有字体 print(pygame.font.get_fonts()) #获取字体对象 font = pygame.font.SysFont('kaiti',18) #绘制字体 textSurface = font.render(text, True, TEXT_COLOR) def getEvent(self): #获取所有事件 eventList = pygame.event.get() #遍历事件 for event in eventList: #判断键盘按下的是关闭还是键盘按下 #如果是关闭退出 if event.type == pygame.QUIT: self.endGame() #如果是按下键 if event.type == pygame.KEYDOWN: #判断上下左右 if event.key == pygame.K_LEFT: print("按下左键向左运动") elif event.key == pygame.K_RIGHT: print("按下右键向右运动") elif event.key == pygame.K_UP: print("按下上键向上运动") elif event.key == pygame.K_DOWN: print("按下下键向下运动") class Tank(): def __init__(self): pass # 移动 def move(self): pass # 射击 def shot(self): pass # 展示坦克的方法 def displayTank(self): pass class MyTank(Tank): def __init__(self): pass class EnemyTank(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 play(self): pass if __name__ == '__main__': MainGame().startGame() #MainGame().getTextSurface()
老师我的window为什么一直是none
老师 这儿为什么有两个lines 代表什么
老师,请问一下这是什么原因,引用了还是报错
老师,这个有点不明白,难道__str__自动会执行??
这个问什么报错了?
#coding=utf-8 import os def getAllFiles(path,level): all_files = os.listdir(path) for filepath in all_files: # filepath = os.path.join(path,file) print("\t" * level + filepath) if os.path.isdir(filepath): getAllFiles(filepath,level+1) getAllFiles(os.getcwd(),0)
这段代码有什么问题吗?为什么输出不了更下一层的文件啊?
如果稍微改动一下,把注释部分取消注释则可以正常输出全部内容,这是什么情况?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637