python挖矿软件,微信挖矿小游戏
你好,吴登盛是吴登盛还是吴登盛。
范仲淹,范仲淹:
importpygame,sys,random,time。汇入游戏,系统,随机,时间
pygame.init()
screen=pygame。展示。set _ mode((660,640))
pygame.display.set_caption(是陈友谅)#什么事
gemmg=pygame。形象。加载( gem。png )#是绿筠
heroimg=pygame。形象。载(‘英雄。png )#阿叔
gameover BG=pygame。形象。load( gameover。png )#你好
bgimg=pygame。形象。加载( BG。png )#乌七
myfont=pygame。字体。系统字体( kait ti ,30)
声音=pygame。搅拌机。声音(运动音乐。wav’).
pygame。搅拌机。音乐。load( bgmusic。MP3’)中绿筠小姐
pygame.mixer.music.play(-1)
heroRect=pygame .直线(270,0,80,80)
朱庇特朱庇特:
gemreclist=[]#是苏秦
数字=0#阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁阿梁
start=False#False你是说.真的阿贺瑞伯
#吴邦国直的哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟哟
forifrinrange(5):
x=随机。兰德整数(0.610)
y=随机。拉尼特(30.590)
gemRect=pygame .直线(x,y,50,50)
gemreclist。追加(gemrect)
ly: 微软雅黑, "Microsoft YaHei";">
是否继续上一次游戏的代码:
whileTrue:foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
pygame.quit()
sys.exit()
elifevent.type==pygame.KEYDOWN:
ifevent.key==pygame.K_y:
withopen("record.txt","r")asfile:
number=int(file.read())
start=True
elifevent.key==pygame.K_n:
start=True
screen.fill((0,0,0))
myWord="是否继续上次的游戏成绩?y/n"
text=myFont.render(myWord,True,(255,0,0))
screen.blit(text,(130,280))
ifstart==True:
break
pygame.display.update()
把结尾写一下:
t1=time.time()whileTrue:
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
pygame.quit()
sys.exit()
elifevent.type==pygame.KEYDOWN:
sound.play()
ifevent.key==pygame.K_UPandheroRect.y>0:
heroRect.y=heroRect.y-40
elifevent.key==pygame.K_DOWNandheroRect.y<560:
heroRect.y=heroRect.y+40
elifevent.key==pygame.K_LEFTandheroRect.x>0:
heroRect.x=heroRect.x-40
elifevent.key==pygame.K_RIGHTandheroRect.x<560:
heroRect.x=heroRect.x+40
t2=time.time()
t=t2-t1#t表示经过的时间
#绘制地图
screen.blit(bgImg,(0,0))
#绘制宝石
forningemRectList:
ifn.colliderect(heroRect):
number=number+1
n.x=random.randint(0,610)
n.y=random.randint(40,590)
screen.blit(gemImg,n)
#绘制英雄
screen.blit(heroImg,heroRect)
#绘制字体
myWord="挖到的宝石数:"+str(number)
myText=myFont.render(myWord,True,(0,0,0))
screen.blit(myText,(420,10))
myWord="剩余时间:"+str(int(20-t))
myText=myFont.render(myWord,True,(0,0,0))
screen.blit(myText,(10,10))
#时间结束,游戏结束,保存成绩,显示成绩
ifint(t)>=20:
withopen("record.txt","w")asfile:
file.write(str(number))
screen.blit(gameoverbg,(0,0))
myWord="时间到了,你的成绩为:"+str(number)
myText=myFont.render(myWord,True,(0,0,0))
screen.blit(myText,(160,80))
pygame.display.update()
完成!
完整代码:
importpygame,sys,random,timepygame.init()
screen=pygame.display.set_mode((660,640))
pygame.display.set_caption("宝石矿工")#标题
gemImg=pygame.image.load("gem.png")#宝石
heroImg=pygame.image.load("hero.png")#挖矿者
gameoverbg=pygame.image.load("gameover.png")#失败提示
bgImg=pygame.image.load("bg.png")#背景
myFont=pygame.font.SysFont("kaiti",30)
sound=pygame.mixer.Sound("moveMusic.wav")
pygame.mixer.music.load("bgMusic.mp3")#背景音乐
pygame.mixer.music.play(-1)
heroRect=pygame.Rect(270,0,80,80)
gemRectList=[]#宝石列表
number=0#挖到的宝石数量
start=False#False表示不退出第一层循环,True表示退出
#创建宝石Rect列表
foriinrange(5):
x=random.randint(0,610)
y=random.randint(30,590)
gemRect=pygame.Rect(x,y,50,50)
gemRectList.append(gemRect)
whileTrue:
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
pygame.quit()
sys.exit()
elifevent.type==pygame.KEYDOWN:
ifevent.key==pygame.K_y:
withopen("record.txt","r")asfile:
number=int(file.read())
start=True
elifevent.key==pygame.K_n:
start=True
screen.fill((0,0,0))
myWord="是否继续上次的游戏成绩?y/n"
text=myFont.render(myWord,True,(255,0,0))
screen.blit(text,(130,280))
ifstart==True:
break
pygame.display.update()
t1=time.time()
whileTrue:
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
pygame.quit()
sys.exit()
elifevent.type==pygame.KEYDOWN:
sound.play()
ifevent.key==pygame.K_UPandheroRect.y>0:
heroRect.y=heroRect.y-40
elifevent.key==pygame.K_DOWNandheroRect.y<560:
heroRect.y=heroRect.y+40
elifevent.key==pygame.K_LEFTandheroRect.x>0:
heroRect.x=heroRect.x-40
elifevent.key==pygame.K_RIGHTandheroRect.x<560:
heroRect.x=heroRect.x+40
t2=time.time()
t=t2-t1#t表示经过的时间
#绘制地图
screen.blit(bgImg,(0,0))
#绘制宝石
forningemRectList:
ifn.colliderect(heroRect):
number=number+1
n.x=random.randint(0,610)
n.y=random.randint(40,590)
screen.blit(gemImg,n)
#绘制英雄
screen.blit(heroImg,heroRect)
#绘制字体
myWord="挖到的宝石数:"+str(number)
myText=myFont.render(myWord,True,(0,0,0))
screen.blit(myText,(420,10))
myWord="剩余时间:"+str(int(20-t))
myText=myFont.render(myWord,True,(0,0,0))
screen.blit(myText,(10,10))
#时间结束,游戏结束,保存成绩,显示成绩
ifint(t)>=20:
withopen("record.txt","w")asfile:
file.write(str(number))
screen.blit(gameoverbg,(0,0))
myWord="时间到了,你的成绩为:"+str(number)
myText=myFont.render(myWord,True,(0,0,0))
screen.blit(myText,(160,80))
pygame.display.update()
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。