本篇文章给大家谈谈python200行有趣小程序,以及python简单小游戏代码,希望对各位有所帮助,不要忘了收藏本站喔。
来源丨网络
经常听到有朋友说,学习编程是一件非常枯燥无味的事情。其实,大家有没有认真想过,可能是我们的学习方法不对?
比方说,你有没有想过,可以通过打游戏来学编程?
今天我想跟大家分享几个Python小游戏,教你如何通过边打游戏边学编程!
1、吃金币
源码分享:
importosimportcfgimportsysimportpygameimportrandomfrommodulesimport*'''游戏初始化'''definitGame():#初始化pygame,设置展示窗口pygame.init()screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('catchcoins——九歌')#加载必要的游戏素材game_images={}forkey,valueincfg.IMAGE_PATHS.items():ifisinstance(value,list):images=[]foriteminvalue:images.append(pygame.image.load(item))game_images[key]=imageselse:game_images[key]=pygame.image.load(value)game_sounds={}forkey,valueincfg.AUDIO_PATHS.items():ifkey=='bgm':continuegame_sounds[key]=pygame.mixer.Sound(value)#返回初始化数据returnscreen,game_images,game_sounds'''主函数'''defmain():#初始化screen,game_images,game_sounds=initGame()#播放背景音乐pygame.mixer.music.load(cfg.AUDIO_PATHS['bgm'])pygame.mixer.music.play(-1,0.0)#字体加载font=pygame.font.Font(cfg.FONT_PATH,40)#定义herohero=Hero(game_images['hero'],position=(375,520))#定义食物组food_sprites_group=pygame.sprite.Group()generate_food_freq=random.randint(10,20)generate_food_count=0#当前分数/历史最高分score=0highest_score=0ifnotos.path.exists(cfg.HIGHEST_SCORE_RECORD_FILEPATH)elseint(open(cfg.HIGHEST_SCORE_RECORD_FILEPATH).read())#游戏主循环clock=pygame.time.Clock()whileTrue:#--填充背景screen.fill(0)screen.blit(game_images['background'],(0,0))#--倒计时信息countdown_text='Countdown:'+str((90000-pygame.time.get_ticks())//60000)+":"+str((90000-pygame.time.get_ticks())//1000%60).zfill(2)countdown_text=font.render(countdown_text,True,(0,0,0))countdown_rect=countdown_text.get_rect()countdown_rect.topright=[cfg.SCREENSIZE[0]-30,5]screen.blit(countdown_text,countdown_rect)#--按键检测foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()key_pressed=pygame.key.get_pressed()ifkey_pressed[pygame.K_a]orkey_pressed[pygame.K_LEFT]:hero.move(cfg.SCREENSIZE,'left')ifkey_pressed[pygame.K_d]orkey_pressed[pygame.K_RIGHT]:hero.move(cfg.SCREENSIZE,'right')#--随机生成食物generate_food_count+=1ifgenerate_food_count>generate_food_freq:generate_food_freq=random.randint(10,20)generate_food_count=0food=Food(game_images,random.choice(['gold',]*10+['apple']),cfg.SCREENSIZE)food_sprites_group.add(food)#--更新食物forfoodinfood_sprites_group:iffood.update():food_sprites_group.remove(food)#--碰撞检测forfoodinfood_sprites_group:ifpygame.sprite.collide_mask(food,hero):game_sounds['get'].play()food_sprites_group.remove(food)score+=food.scoreifscore>highest_score:highest_score=score#--画herohero.draw(screen)#--画食物food_sprites_group.draw(screen)#--显示得分score_text=f'Score:{score},Highest:{highest_score}'score_text=font.render(score_text,True,(0,0,0))score_rect=score_text.get_rect()score_rect.topleft=[5,5]screen.blit(score_text,score_rect)#--判断游戏是否结束ifpygame.time.get_ticks()>=90000:break#--更新屏幕pygame.display.flip()clock.tick(cfg.FPS)#游戏结束,记录最高分并显示游戏结束画面fp=open(cfg.HIGHEST_SCORE_RECORD_FILEPATH,'w')fp.write(str(highest_score))fp.close()returnshowEndGameInterface(screen,cfg,score,highest_score)'''run'''if__name__=='__main__':whilemain():pass
2、打乒乓
源码分享:
importsysimportcfgimportpygamefrommodulesimport*'''定义按钮'''defButton(screen,position,text,button_size=(200,50)):left,top=positionbwidth,bheight=button_sizepygame.draw.line(screen,(150,150,150),(left,top),(left+bwidth,top),5)pygame.draw.line(screen,(150,150,150),(left,top-2),(left,top+bheight),5)pygame.draw.line(screen,(50,50,50),(left,top+bheight),(left+bwidth,top+bheight),5)pygame.draw.line(screen,(50,50,50),(left+bwidth,top+bheight),(left+bwidth,top),5)pygame.draw.rect(screen,(100,100,100),(left,top,bwidth,bheight))font=pygame.font.Font(cfg.FONTPATH,30)text_render=font.render(text,1,(255,235,205))returnscreen.blit(text_render,(left+50,top+10))'''Function:开始界面Input:--screen:游戏界面Return:--game_mode:1(单人模式)/2(双人模式)'''defstartInterface(screen):clock=pygame.time.Clock()whileTrue:screen.fill((41,36,33))button_1=Button(screen,(150,175),'1Player')button_2=Button(screen,(150,275),'2Player')foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()ifevent.type==pygame.MOUSEBUTTONDOWN:ifbutton_1.collidepoint(pygame.mouse.get_pos()):return1elifbutton_2.collidepoint(pygame.mouse.get_pos()):return2clock.tick(10)pygame.display.update()'''结束界面'''defendInterface(screen,score_left,score_right):clock=pygame.time.Clock()font1=pygame.font.Font(cfg.FONTPATH,30)font2=pygame.font.Font(cfg.FONTPATH,20)msg='Playeronleftwon!'ifscore_left>score_rightelse'Playeronrightwon!'texts=[font1.render(msg,True,cfg.WHITE),font2.render('PressESCAPEtoquit.',True,cfg.WHITE),font2.render('PressENTERtocontinueorplayagain.',True,cfg.WHITE)]positions=[[120,200],[155,270],[80,300]]whileTrue:screen.fill((41,36,33))foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()ifevent.type==pygame.KEYDOWN:ifevent.key==pygame.K_RETURN:returnelifevent.key==pygame.K_ESCAPE:sys.exit()pygame.quit()fortext,posinzip(texts,positions):screen.blit(text,pos)clock.tick(10)pygame.display.update()'''运行游戏Demo'''defrunDemo(screen):#加载游戏素材hit_sound=pygame.mixer.Sound(cfg.HITSOUNDPATH)goal_sound=pygame.mixer.Sound(cfg.GOALSOUNDPATH)pygame.mixer.music.load(cfg.BGMPATH)pygame.mixer.music.play(-1,0.0)font=pygame.font.Font(cfg.FONTPATH,50)#开始界面game_mode=startInterface(screen)#游戏主循环#--左边球拍(ws控制,仅双人模式时可控制)score_left=0racket_left=Racket(cfg.RACKETPICPATH,'LEFT',cfg)#--右边球拍(↑↓控制)score_right=0racket_right=Racket(cfg.RACKETPICPATH,'RIGHT',cfg)#--球ball=Ball(cfg.BALLPICPATH,cfg)clock=pygame.time.Clock()whileTrue:foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit(-1)screen.fill((41,36,33))#玩家操作pressed_keys=pygame.key.get_pressed()ifpressed_keys[pygame.K_UP]:racket_right.move('UP')elifpressed_keys[pygame.K_DOWN]:racket_right.move('DOWN')ifgame_mode==2:ifpressed_keys[pygame.K_w]:racket_left.move('UP')elifpressed_keys[pygame.K_s]:racket_left.move('DOWN')else:racket_left.automove(ball)#球运动scores=ball.move(ball,racket_left,racket_right,hit_sound,goal_sound)score_left+=scores[0]score_right+=scores[1]#显示#--分隔线pygame.draw.rect(screen,cfg.WHITE,(247,0,6,500))#--球ball.draw(screen)#--拍racket_left.draw(screen)racket_right.draw(screen)#--得分screen.blit(font.render(str(score_left),False,cfg.WHITE),(150,10))screen.blit(font.render(str(score_right),False,cfg.WHITE),(300,10))ifscore_left==11orscore_right==11:returnscore_left,score_rightclock.tick(100)pygame.display.update()'''主函数'''defmain():#初始化pygame.init()pygame.mixer.init()screen=pygame.display.set_mode((cfg.WIDTH,cfg.HEIGHT))pygame.display.set_caption('pingpong——九歌')#开始游戏whileTrue:score_left,score_right=runDemo(screen)endInterface(screen,score_left,score_right)'''run'''if__name__=='__main__':main()
3、滑雪
源码分享:
importsysimportcfgimportpygameimportrandom'''滑雪者类'''classSkierClass(pygame.sprite.Sprite):def__init__(self):pygame.sprite.Sprite.__init__(self)#滑雪者的朝向(-2到2)self.direction=0self.imagepaths=cfg.SKIER_IMAGE_PATHS[:-1]self.image=pygame.image.load(self.imagepaths[self.direction])self.rect=self.image.get_rect()self.rect.center=[320,100]self.speed=[self.direction,6-abs(self.direction)*2]'''改变滑雪者的朝向.负数为向左,正数为向右,0为向前'''defturn(self,num):self.direction+=numself.direction=max(-2,self.direction)self.direction=min(2,self.direction)center=self.rect.centerself.image=pygame.image.load(self.imagepaths[self.direction])self.rect=self.image.get_rect()self.rect.center=centerself.speed=[self.direction,6-abs(self.direction)*2]returnself.speed'''移动滑雪者'''defmove(self):self.rect.centerx+=self.speed[0]self.rect.centerx=max(20,self.rect.centerx)self.rect.centerx=min(620,self.rect.centerx)'''设置为摔倒状态'''defsetFall(self):self.image=pygame.image.load(cfg.SKIER_IMAGE_PATHS[-1])'''设置为站立状态'''defsetForward(self):self.direction=0self.image=pygame.image.load(self.imagepaths[self.direction])'''Function:障碍物类Input:img_path:障碍物图片路径location:障碍物位置attribute:障碍物类别属性'''classObstacleClass(pygame.sprite.Sprite):def__init__(self,img_path,location,attribute):pygame.sprite.Sprite.__init__(self)self.img_path=img_pathself.image=pygame.image.load(self.img_path)self.location=locationself.rect=self.image.get_rect()self.rect.center=self.locationself.attribute=attributeself.passed=False'''移动'''defmove(self,num):self.rect.centery=self.location[1]-num'''创建障碍物'''defcreateObstacles(s,e,num=10):obstacles=pygame.sprite.Group()locations=[]foriinrange(num):row=random.randint(s,e)col=random.randint(0,9)location=[col*64+20,row*64+20]iflocationnotinlocations:locations.append(location)attribute=random.choice(list(cfg.OBSTACLE_PATHS.keys()))img_path=cfg.OBSTACLE_PATHS[attribute]obstacle=ObstacleClass(img_path,location,attribute)obstacles.add(obstacle)returnobstacles'''合并障碍物'''defAddObstacles(obstacles0,obstacles1):obstacles=pygame.sprite.Group()forobstacleinobstacles0:obstacles.add(obstacle)forobstacleinobstacles1:obstacles.add(obstacle)returnobstacles'''显示游戏开始界面'''defShowStartInterface(screen,screensize):screen.fill((255,255,255))tfont=pygame.font.Font(cfg.FONTPATH,screensize[0]//5)cfont=pygame.font.Font(cfg.FONTPATH,screensize[0]//20)title=tfont.render(u'滑雪游戏',True,(255,0,0))content=cfont.render(u'按任意键开始游戏',True,(0,0,255))trect=title.get_rect()trect.midtop=(screensize[0]/2,screensize[1]/5)crect=content.get_rect()crect.midtop=(screensize[0]/2,screensize[1]/2)screen.blit(title,trect)screen.blit(content,crect)whileTrue:foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()elifevent.type==pygame.KEYDOWN:returnpygame.display.update()'''显示分数'''defshowScore(screen,score,pos=(10,10)):font=pygame.font.Font(cfg.FONTPATH,30)score_text=font.render("Score:%s"%score,True,(0,0,0))screen.blit(score_text,pos)'''更新当前帧的游戏画面'''defupdateFrame(screen,obstacles,skier,score):screen.fill((255,255,255))obstacles.draw(screen)screen.blit(skier.image,skier.rect)showScore(screen,score)pygame.display.update()'''主程序'''defmain():#游戏初始化pygame.init()pygame.mixer.init()pygame.mixer.music.load(cfg.BGMPATH)pygame.mixer.music.set_volume(0.4)pygame.mixer.music.play(-1)#设置屏幕screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('滑雪游戏——九歌')#游戏开始界面ShowStartInterface(screen,cfg.SCREENSIZE)#实例化游戏精灵#--滑雪者skier=SkierClass()#--创建障碍物obstacles0=createObstacles(20,29)obstacles1=createObstacles(10,19)obstaclesflag=0obstacles=AddObstacles(obstacles0,obstacles1)#游戏clockclock=pygame.time.Clock()#记录滑雪的距离distance=0#记录当前的分数score=0#记录当前的速度speed=[0,6]#游戏主循环whileTrue:#--事件捕获foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()ifevent.type==pygame.KEYDOWN:ifevent.key==pygame.K_LEFTorevent.key==pygame.K_a:speed=skier.turn(-1)elifevent.key==pygame.K_RIGHTorevent.key==pygame.K_d:speed=skier.turn(1)#--更新当前游戏帧的数据skier.move()distance+=speed[1]ifdistance>=640andobstaclesflag==0:obstaclesflag=1obstacles0=createObstacles(20,29)obstacles=AddObstacles(obstacles0,obstacles1)ifdistance>=1280andobstaclesflag==1:obstaclesflag=0distance-=1280forobstacleinobstacles0:obstacle.location[1]=obstacle.location[1]-1280obstacles1=createObstacles(10,19)obstacles=AddObstacles(obstacles0,obstacles1)forobstacleinobstacles:obstacle.move(distance)#--碰撞检测hitted_obstacles=pygame.sprite.spritecollide(skier,obstacles,False)ifhitted_obstacles:ifhitted_obstacles[0].attribute=="tree"andnothitted_obstacles[0].passed:score-=50skier.setFall()updateFrame(screen,obstacles,skier,score)pygame.time.delay(1000)skier.setForward()speed=[0,6]hitted_obstacles[0].passed=Trueelifhitted_obstacles[0].attribute=="flag"andnothitted_obstacles[0].passed:score+=10obstacles.remove(hitted_obstacles[0])#--更新屏幕updateFrame(screen,obstacles,skier,score)clock.tick(cfg.FPS)'''run'''if__name__=='__main__': main();
4、并夕夕版飞机大战
源码分享:
importsysimportcfgimportpygamefrommodulesimport*'''游戏界面'''defGamingInterface(num_player,screen):#初始化pygame.mixer.music.load(cfg.SOUNDPATHS['CoolSpaceMusic'])pygame.mixer.music.set_volume(0.4)pygame.mixer.music.play(-1)explosion_sound=pygame.mixer.Sound(cfg.SOUNDPATHS['boom'])fire_sound=pygame.mixer.Sound(cfg.SOUNDPATHS['shot'])font=pygame.font.Font(cfg.FONTPATH,20)#游戏背景图bg_imgs=[cfg.IMAGEPATHS['bg_big'],cfg.IMAGEPATHS['seamless_space'],cfg.IMAGEPATHS['space3']]bg_move_dis=0bg_1=pygame.image.load(bg_imgs[0]).convert()bg_2=pygame.image.load(bg_imgs[1]).convert()bg_3=pygame.image.load(bg_imgs[2]).convert()#玩家,子弹和小行星精灵组player_group=pygame.sprite.Group()bullet_group=pygame.sprite.Group()asteroid_group=pygame.sprite.Group()#产生小行星的时间间隔asteroid_ticks=90foriinrange(num_player):player_group.add(Ship(i+1,cfg))clock=pygame.time.Clock()#分数score_1,score_2=0,0#游戏主循环whileTrue:foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()#--玩家一:↑↓←→控制,j射击;玩家二:wsad控制,空格射击pressed_keys=pygame.key.get_pressed()foridx,playerinenumerate(player_group):direction=Noneifidx==0:ifpressed_keys[pygame.K_UP]:direction='up'elifpressed_keys[pygame.K_DOWN]:direction='down'elifpressed_keys[pygame.K_LEFT]:direction='left'elifpressed_keys[pygame.K_RIGHT]:direction='right'ifdirection:player.move(direction)ifpressed_keys[pygame.K_j]:ifplayer.cooling_time==0:fire_sound.play()bullet_group.add(player.shot())player.cooling_time=20elifidx==1:ifpressed_keys[pygame.K_w]:direction='up'elifpressed_keys[pygame.K_s]:direction='down'elifpressed_keys[pygame.K_a]:direction='left'elifpressed_keys[pygame.K_d]:direction='right'ifdirection:player.move(direction)ifpressed_keys[pygame.K_SPACE]:ifplayer.cooling_time==0:fire_sound.play()bullet_group.add(player.shot())player.cooling_time=20ifplayer.cooling_time>0:player.cooling_time-=1if(score_1+score_2)<500:background=bg_1elif(score_1+score_2)0:ifplayer.explode_step>3:player_group.remove(player)iflen(player_group)==0:returnelse:player.explode(screen)else:player.draw(screen)#--画子弹forbulletinbullet_group:bullet.move()ifpygame.sprite.spritecollide(bullet,asteroid_group,True,None):bullet_group.remove(bullet)ifbullet.player_idx==1:score_1+=1else:score_2+=1else:bullet.draw(screen)#--画小行星forasteroidinasteroid_group:asteroid.move()asteroid.rotate()asteroid.draw(screen)#--显示分数score_1_text='玩家一得分:%s'%score_1score_2_text='玩家二得分:%s'%score_2text_1=font.render(score_1_text,True,(0,0,255))text_2=font.render(score_2_text,True,(255,0,0))screen.blit(text_1,(2,5))screen.blit(text_2,(2,35))#--屏幕刷新pygame.display.update()clock.tick(60)'''主函数'''defmain():pygame.init()pygame.font.init()pygame.mixer.init()screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('飞机大战——九歌')num_player=StartInterface(screen,cfg)ifnum_player==1:whileTrue:GamingInterface(num_player=1,screen=screen)EndInterface(screen,cfg)else:whileTrue:GamingInterface(num_player=2,screen=screen)EndInterface(screen,cfg)'''run'''if__name__=='__main__':main()
5、打地鼠
源码分享:
importcfgimportsysimportpygameimportrandomfrommodulesimport*'''游戏初始化'''definitGame():pygame.init()pygame.mixer.init()screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('打地鼠——九歌')returnscreen'''主函数'''defmain():#初始化screen=initGame()#加载背景音乐和其他音效pygame.mixer.music.load(cfg.BGM_PATH)pygame.mixer.music.play(-1)audios={'count_down':pygame.mixer.Sound(cfg.COUNT_DOWN_SOUND_PATH),'hammering':pygame.mixer.Sound(cfg.HAMMERING_SOUND_PATH)}#加载字体font=pygame.font.Font(cfg.FONT_PATH,40)#加载背景图片bg_img=pygame.image.load(cfg.GAME_BG_IMAGEPATH)#开始界面startInterface(screen,cfg.GAME_BEGIN_IMAGEPATHS)#地鼠改变位置的计时hole_pos=random.choice(cfg.HOLE_POSITIONS)change_hole_event=pygame.USEREVENTpygame.time.set_timer(change_hole_event,800)#地鼠mole=Mole(cfg.MOLE_IMAGEPATHS,hole_pos)#锤子hammer=Hammer(cfg.HAMMER_IMAGEPATHS,(500,250))#时钟clock=pygame.time.Clock()#分数your_score=0flag=False#初始时间init_time=pygame.time.get_ticks()#游戏主循环whileTrue:#--游戏时间为60stime_remain=round((61000-(pygame.time.get_ticks()-init_time))/1000.)#--游戏时间减少,地鼠变位置速度变快iftime_remain==40andnotflag:hole_pos=random.choice(cfg.HOLE_POSITIONS)mole.reset()mole.setPosition(hole_pos)pygame.time.set_timer(change_hole_event,650)flag=Trueeliftime_remain==20andflag:hole_pos=random.choice(cfg.HOLE_POSITIONS)mole.reset()mole.setPosition(hole_pos)pygame.time.set_timer(change_hole_event,500)flag=False#--倒计时音效iftime_remain==10:audios['count_down'].play()#--游戏结束iftime_remainbest_score:f=open(cfg.RECORD_PATH,'w')f.write(str(your_score))f.close()#结束界面score_info={'your_score':your_score,'best_score':best_score}is_restart=endInterface(screen,cfg.GAME_END_IMAGEPATH,cfg.GAME_AGAIN_IMAGEPATHS,score_info,cfg.FONT_PATH,[cfg.WHITE,cfg.RED],cfg.SCREENSIZE)returnis_restart'''run'''if__name__=='__main__':whileTrue:is_restart=main()ifnotis_restart:break
6、小恐龙
玩法:上下控制起跳躲避
源码分享:
importcfgimportsysimportrandomimportpygamefrommodulesimport*'''main'''defmain(highest_score):#游戏初始化pygame.init()screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('九歌')#导入所有声音文件sounds={}forkey,valueincfg.AUDIO_PATHS.items():sounds[key]=pygame.mixer.Sound(value)#游戏开始界面GameStartInterface(screen,sounds,cfg)#定义一些游戏中必要的元素和变量score=0score_board=Scoreboard(cfg.IMAGE_PATHS['numbers'],position=(534,15),bg_color=cfg.BACKGROUND_COLOR)highest_score=highest_scorehighest_score_board=Scoreboard(cfg.IMAGE_PATHS['numbers'],position=(435,15),bg_color=cfg.BACKGROUND_COLOR,is_highest=True)dino=Dinosaur(cfg.IMAGE_PATHS['dino'])ground=Ground(cfg.IMAGE_PATHS['ground'],position=(0,cfg.SCREENSIZE[1]))cloud_sprites_group=pygame.sprite.Group()cactus_sprites_group=pygame.sprite.Group()ptera_sprites_group=pygame.sprite.Group()add_obstacle_timer=0score_timer=0#游戏主循环clock=pygame.time.Clock()whileTrue:foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()elifevent.type==pygame.KEYDOWN:ifevent.key==pygame.K_SPACEorevent.key==pygame.K_UP:dino.jump(sounds)elifevent.key==pygame.K_DOWN:dino.duck()elifevent.type==pygame.KEYUPandevent.key==pygame.K_DOWN:dino.unduck()screen.fill(cfg.BACKGROUND_COLOR)#--随机添加云iflen(cloud_sprites_group)random.randrange(50,150):add_obstacle_timer=0random_value=random.randrange(0,10)ifrandom_value>=5andrandom_value(cfg.FPS//12):score_timer=0score+=1score=min(score,99999)ifscore>highest_score:highest_score=scoreifscore%100==0:sounds['point'].play()ifscore%1000==0:ground.speed-=1foritemincloud_sprites_group:item.speed-=1foritemincactus_sprites_group:item.speed-=1foriteminptera_sprites_group:item.speed-=1#--碰撞检测foritemincactus_sprites_group:ifpygame.sprite.collide_mask(dino,item):dino.die(sounds)foriteminptera_sprites_group:ifpygame.sprite.collide_mask(dino,item):dino.die(sounds)#--将游戏元素画到屏幕上dino.draw(screen)ground.draw(screen)cloud_sprites_group.draw(screen)cactus_sprites_group.draw(screen)ptera_sprites_group.draw(screen)score_board.set(score)highest_score_board.set(highest_score)score_board.draw(screen)highest_score_board.draw(screen)#--更新屏幕pygame.display.update()clock.tick(cfg.FPS)#--游戏是否结束ifdino.is_dead:break#游戏结束界面returnGameEndInterface(screen,cfg),highest_score'''run'''if__name__=='__main__':highest_score=0whileTrue:flag,highest_score=main(highest_score)ifnotflag:break
7、消消乐
玩法:三个相连就能消除
源码分享:
importosimportsysimportcfgimportpygamefrommodulesimport*'''游戏主程序'''defmain():pygame.init()screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('Gemgem——九歌')#加载背景音乐pygame.mixer.init()pygame.mixer.music.load(os.path.join(cfg.ROOTDIR,"resources/audios/bg.mp3"))pygame.mixer.music.set_volume(0.6)pygame.mixer.music.play(-1)#加载音效sounds={}sounds['mismatch']=pygame.mixer.Sound(os.path.join(cfg.ROOTDIR,'resources/audios/badswap.wav'))sounds['match']=[]foriinrange(6):sounds['match'].append(pygame.mixer.Sound(os.path.join(cfg.ROOTDIR,'resources/audios/match%s.wav'%i)))#加载字体font=pygame.font.Font(os.path.join(cfg.ROOTDIR,'resources/font/font.TTF'),25)#图片加载gem_imgs=[]foriinrange(1,8):gem_imgs.append(os.path.join(cfg.ROOTDIR,'resources/images/gem%s.png'%i))#主循环game=gemGame(screen,sounds,font,gem_imgs,cfg)whileTrue:score=game.start()flag=False#一轮游戏结束后玩家选择重玩或者退出whileTrue:foreventinpygame.event.get():ifevent.type==pygame.QUITor(event.type==pygame.KEYUPandevent.key==pygame.K_ESCAPE):pygame.quit()sys.exit()elifevent.type==pygame.KEYUPandevent.key==pygame.K_r:flag=Trueifflag:breakscreen.fill((135,206,235))text0='Finalscore:%s'%scoretext1='Presstorestartthegame.'text2='Presstoquitthegame.'y=150foridx,textinenumerate([text0,text1,text2]):text_render=font.render(text,1,(85,65,0))rect=text_render.get_rect()ifidx==0:rect.left,rect.top=(212,y)elifidx==1:rect.left,rect.top=(122.5,y)else:rect.left,rect.top=(126.5,y)y+=100screen.blit(text_render,rect)pygame.display.update()game.reset()'''run'''if__name__=='__main__':main()
8、俄罗斯方块
玩法:童年经典,普通模式没啥意思,小时候我们都是玩加速的AI同义句转换好用的句子同义替换软件。
源码分享:
importosimportsysimportrandomfrommodulesimport*fromPyQt5.QtGuiimport*fromPyQt5.QtCoreimport*fromPyQt5.QtWidgetsimport*'''定义俄罗斯方块游戏类'''classTetrisGame(QMainWindow):def__init__(self,parent=None):super(TetrisGame,self).__init__(parent)#是否暂停ingself.is_paused=False#是否开始ingself.is_started=Falseself.initUI()'''界面初始化'''definitUI(self):#iconself.setWindowIcon(QIcon(os.path.join(os.getcwd(),'resources/icon.jpg')))#块大小self.grid_size=22#游戏帧率self.fps=200self.timer=QBasicTimer()#焦点self.setFocusPolicy(Qt.StrongFocus)#水平布局layout_horizontal=QHBoxLayout()self.inner_board=InnerBoard()self.external_board=ExternalBoard(self,self.grid_size,self.inner_board)layout_horizontal.addWidget(self.external_board)self.side_panel=SidePanel(self,self.grid_size,self.inner_board)layout_horizontal.addWidget(self.side_panel)self.status_bar=self.statusBar()self.external_board.score_signal[str].connect(self.status_bar.showMessage)self.start()self.center()self.setWindowTitle('Tetris——九歌')self.show()self.setFixedSize(self.external_board.width()+self.side_panel.width(),self.side_panel.height()+self.status_bar.height())'''游戏界面移动到屏幕中间'''defcenter(self):screen=QDesktopWidget().screenGeometry()size=self.geometry()self.move((screen.width()-size.width())//2,(screen.height()-size.height())//2)'''更新界面'''defupdateWindow(self):self.external_board.updateData()self.side_panel.updateData()self.update()'''开始'''defstart(self):ifself.is_started:returnself.is_started=Trueself.inner_board.createNewTetris()self.timer.start(self.fps,self)'''暂停/不暂停'''defpause(self):ifnotself.is_started:returnself.is_paused=notself.is_pausedifself.is_paused:self.timer.stop()self.external_board.score_signal.emit('Paused')else:self.timer.start(self.fps,self)self.updateWindow()'''计时器事件'''deftimerEvent(self,event):ifevent.timerId()==self.timer.timerId():removed_lines=self.inner_board.moveDown()self.external_board.score+=removed_linesself.updateWindow()else:super(TetrisGame,self).timerEvent(event)'''按键事件'''defkeyPressEvent(self,event):ifnotself.is_startedorself.inner_board.current_tetris==tetrisShape().shape_empty:super(TetrisGame,self).keyPressEvent(event)returnkey=event.key()#P键暂停ifkey==Qt.Key_P:self.pause()returnifself.is_paused:return#向左elifkey==Qt.Key_Left:self.inner_board.moveLeft()#向右elifkey==Qt.Key_Right:self.inner_board.moveRight()#旋转elifkey==Qt.Key_Up:self.inner_board.rotateAnticlockwise()#快速坠落elifkey==Qt.Key_Space:self.external_board.score+=self.inner_board.dropDown()else:super(TetrisGame,self).keyPressEvent(event)self.updateWindow()'''run'''if__name__=='__main__':app=QApplication([])tetris=TetrisGame()sys.exit(app.exec_())
9、贪吃蛇
玩法:童年经典,普通魔术也没啥意思,小时候玩的也是加速的。
源码分享:
importcfgimportsysimportpygamefrommodulesimport*'''主函数'''defmain(cfg):#游戏初始化pygame.init()screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('GreedySnake——九歌')clock=pygame.time.Clock()#播放背景音乐pygame.mixer.music.load(cfg.BGMPATH)pygame.mixer.music.play(-1)#游戏主循环snake=Snake(cfg)apple=Apple(cfg,snake.coords)score=0whileTrue:screen.fill(cfg.BLACK)#--按键检测foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit()elifevent.type==pygame.KEYDOWN:ifevent.keyin[pygame.K_UP,pygame.K_DOWN,pygame.K_LEFT,pygame.K_RIGHT]:snake.setDirection({pygame.K_UP:'up',pygame.K_DOWN:'down',pygame.K_LEFT:'left',pygame.K_RIGHT:'right'}[event.key])#--更新贪吃蛇和食物ifsnake.update(apple):apple=Apple(cfg,snake.coords)score+=1#--判断游戏是否结束ifsnake.isgameover:break#--显示游戏里必要的元素drawGameGrid(cfg,screen)snake.draw(screen)apple.draw(screen)showScore(cfg,score,screen)#--屏幕更新pygame.display.update()clock.tick(cfg.FPS)returnendInterface(screen,cfg)'''run'''if__name__=='__main__':whileTrue:ifnotmain(cfg):break
10、24点小游戏
玩法:通过加减乘除操作,小学生都没问题的。
源码分享:
importosimportsysimportpygamefromcfgimport*frommodulesimport*fromfractionsimportFraction'''检查控件是否被点击'''defcheckClicked(group,mouse_pos,group_type='NUMBER'):selected=[]#数字卡片/运算符卡片ifgroup_type==GROUPTYPES[0]orgroup_type==GROUPTYPES[1]:max_selected=2ifgroup_type==GROUPTYPES[0]else1num_selected=0foreachingroup:num_selected+=int(each.is_selected)foreachingroup:ifeach.rect.collidepoint(mouse_pos):ifeach.is_selected:each.is_selected=noteach.is_selectednum_selected-=1each.select_order=Noneelse:ifnum_selected<max_selected:each.is_selected=noteach.is_selectednum_selected+=1each.select_order=str(num_selected)ifeach.is_selected:selected.append(each.attribute)#按钮卡片elifgroup_type==GROUPTYPES[2]:foreachingroup:ifeach.rect.collidepoint(mouse_pos):each.is_selected=Trueselected.append(each.attribute)#抛出异常else:raiseValueError('checkClicked.group_typeunsupport%s,expect%s,%sor%s...'%(group_type,*GROUPTYPES))returnselected'''获取数字精灵组'''defgetNumberSpritesGroup(numbers):number_sprites_group=pygame.sprite.Group()foridx,numberinenumerate(numbers):args=(*NUMBERCARD_POSITIONS[idx],str(number),NUMBERFONT,NUMBERFONT_COLORS,NUMBERCARD_COLORS,str(number))number_sprites_group.add(Card(*args))returnnumber_sprites_group'''获取运算符精灵组'''defgetOperatorSpritesGroup(operators):operator_sprites_group=pygame.sprite.Group()foridx,operatorinenumerate(operators):args=(*OPERATORCARD_POSITIONS[idx],str(operator),OPERATORFONT,OPREATORFONT_COLORS,OPERATORCARD_COLORS,str(operator))operator_sprites_group.add(Card(*args))returnoperator_sprites_group'''获取按钮精灵组'''defgetButtonSpritesGroup(buttons):button_sprites_group=pygame.sprite.Group()foridx,buttoninenumerate(buttons):args=(*BUTTONCARD_POSITIONS[idx],str(button),BUTTONFONT,BUTTONFONT_COLORS,BUTTONCARD_COLORS,str(button))button_sprites_group.add(Button(*args))returnbutton_sprites_group'''计算'''defcalculate(number1,number2,operator):operator_map={'+':'+','-':'-','×':'*','÷':'/'}try:result=str(eval(number1+operator_map[operator]+number2))returnresultif'.'notinresultelsestr(Fraction(number1+operator_map[operator]+number2))except:returnNone'''在屏幕上显示信息'''defshowInfo(text,screen):rect=pygame.Rect(200,180,400,200)pygame.draw.rect(screen,PAPAYAWHIP,rect)font=pygame.font.Font(FONTPATH,40)text_render=font.render(text,True,BLACK)font_size=font.size(text)screen.blit(text_render,(rect.x+(rect.width-font_size[0])/2,rect.y+(rect.height-font_size[1])/2))'''主函数'''defmain():#初始化,导入必要的游戏素材pygame.init()pygame.mixer.init()screen=pygame.display.set_mode(SCREENSIZE)pygame.display.set_caption('24point——九歌')win_sound=pygame.mixer.Sound(AUDIOWINPATH)lose_sound=pygame.mixer.Sound(AUDIOLOSEPATH)warn_sound=pygame.mixer.Sound(AUDIOWARNPATH)pygame.mixer.music.load(BGMPATH)pygame.mixer.music.play(-1,0.0)#24点游戏生成器game24_gen=game24Generator()game24_gen.generate()#精灵组#--数字number_sprites_group=getNumberSpritesGroup(game24_gen.numbers_now)#--运算符operator_sprites_group=getOperatorSpritesGroup(OPREATORS)#--按钮button_sprites_group=getButtonSpritesGroup(BUTTONS)#游戏主循环clock=pygame.time.Clock()selected_numbers=[]selected_operators=[]selected_buttons=[]is_win=FalsewhileTrue:foreventinpygame.event.get():ifevent.type==pygame.QUIT:pygame.quit()sys.exit(-1)elifevent.type==pygame.MOUSEBUTTONUP:mouse_pos=pygame.mouse.get_pos()selected_numbers=checkClicked(number_sprites_group,mouse_pos,'NUMBER')selected_operators=checkClicked(operator_sprites_group,mouse_pos,'OPREATOR')selected_buttons=checkClicked(button_sprites_group,mouse_pos,'BUTTON')screen.fill(AZURE)#更新数字iflen(selected_numbers)==2andlen(selected_operators)==1:noselected_numbers=[]foreachinnumber_sprites_group:ifeach.is_selected:ifeach.select_order=='1':selected_number1=each.attributeelifeach.select_order=='2':selected_number2=each.attributeelse:raiseValueError('Unknowselect_order%s,expect1or2...'%each.select_order)else:noselected_numbers.append(each.attribute)each.is_selected=Falseforeachinoperator_sprites_group:each.is_selected=Falseresult=calculate(selected_number1,selected_number2,*selected_operators)ifresultisnotNone:game24_gen.numbers_now=noselected_numbers+[result]is_win=game24_gen.check()ifis_win:win_sound.play()ifnotis_winandlen(game24_gen.numbers_now)==1:lose_sound.play()else:warn_sound.play()selected_numbers=[]selected_operators=[]number_sprites_group=getNumberSpritesGroup(game24_gen.numbers_now)#精灵都画到screen上foreachinnumber_sprites_group:each.draw(screen,pygame.mouse.get_pos())foreachinoperator_sprites_group:each.draw(screen,pygame.mouse.get_pos())foreachinbutton_sprites_group:ifselected_buttonsandselected_buttons[0]in['RESET','NEXT']:is_win=Falseifselected_buttonsandeach.attribute==selected_buttons[0]:each.is_selected=Falsenumber_sprites_group=each.do(game24_gen,getNumberSpritesGroup,number_sprites_group,button_sprites_group)selected_buttons=[]each.draw(screen,pygame.mouse.get_pos())#游戏胜利ifis_win:showInfo('Congratulations',screen)#游戏失败ifnotis_winandlen(game24_gen.numbers_now)==1:showInfo('GameOver',screen)pygame.display.flip()clock.tick(30)'''run'''if__name__=='__main__':main()
11、平衡木
玩法:也是小时候的经典游戏,控制左右就行,到后面才有一点点难度。
源码分享:
importcfgfrommodulesimportbreakoutClone'''主函数'''defmain():game=breakoutClone(cfg)game.run()'''run'''if__name__=='__main__':main()
12、外星人入侵
玩法:这让我想起了魂斗罗那第几关的boss,有点类似,不过魂斗罗那个难度肯定高点。
源码分享:
importosimportsysimportcfgimportrandomimportpygamefrommodulesimport*'''开始游戏'''defstartGame(screen):clock=pygame.time.Clock()#加载字体font=pygame.font.SysFont('arial',18)ifnotos.path.isfile('score'):f=open('score','w')f.write('0')f.close()withopen('score','r')asf:highest_score=int(f.read().strip())#敌方enemies_group=pygame.sprite.Group()foriinrange(55):ifi<11:enemy=enemySprite('small',i,cfg.WHITE,cfg.WHITE)elifienemy_shot_interval:enemy_shot_flag=Trueenemies_survive_list=[enemy.numberforenemyinenemies_group]shot_number=random.choice(enemies_survive_list)enemy_shot_count=0#----敌方移动enemy_move_count+=1ifenemy_move_count>enemy_move_interval:enemy_move_count=0enemy_move_flag=Trueenemy_need_move_row-=1ifenemy_need_move_row==0:enemy_need_move_row=enemy_max_rowenemy_change_direction_count+=1ifenemy_change_direction_count>enemy_change_direction_interval:enemy_change_direction_count=1enemy_move_right=notenemy_move_rightenemy_need_down=True#----每次下降提高移动和射击速度enemy_move_interval=max(15,enemy_move_interval-3)enemy_shot_interval=max(50,enemy_move_interval-10)#----遍历更新forenemyinenemies_group:ifenemy_shot_flag:ifenemy.number==shot_number:en_bullet=enemy.shot()en_bullets_group.add(en_bullet)ifenemy_move_flag:ifenemy.numberinrange((enemy_need_move_row-1)*11,enemy_need_move_row*11):ifenemy_move_right:enemy.update('right',cfg.SCREENSIZE[1])else:enemy.update('left',cfg.SCREENSIZE[1])else:enemy.update(None,cfg.SCREENSIZE[1])ifenemy_need_down:ifenemy.update('down',cfg.SCREENSIZE[1]):running=Falseis_win=Falseenemy.change_count-=1enemy.draw(screen)enemy_move_flag=Falseenemy_need_down=Falseenemy_shot_flag=False#----敌方爆炸特效forboomed_enemyinboomed_enemies_group:ifboomed_enemy.boom(screen):boomed_enemies_group.remove(boomed_enemy)delboomed_enemy#--敌方子弹与我方飞船碰撞检测ifnotmyaircraft.one_dead:ifpygame.sprite.spritecollide(myaircraft,en_bullets_group,True,None):myaircraft.one_dead=Trueifmyaircraft.one_dead:ifmyaircraft.boom(screen):myaircraft.resetBoom()myaircraft.num_life-=1ifmyaircraft.num_lifehighest_score:highest_score=myaircraft.score#--得分每增加2000我方飞船增加一条生命if(myaircraft.score%2000==0)and(myaircraft.score>0)and(myaircraft.score!=myaircraft.old_score):myaircraft.old_score=myaircraft.scoremyaircraft.num_life=min(myaircraft.num_life+1,myaircraft.max_num_life)#--敌人都死光了的话就胜利了iflen(enemies_group)<1:is_win=Truerunning=False#--显示文字#----当前得分showText(screen,'SCORE:',cfg.WHITE,font,200,8)showText(screen,str(myaircraft.score),cfg.WHITE,font,200,24)#----敌人数量showText(screen,'ENEMY:',cfg.WHITE,font,370,8)showText(screen,str(len(enemies_group)),cfg.WHITE,font,370,24)#----历史最高分showText(screen,'HIGHEST:',cfg.WHITE,font,540,8)showText(screen,str(highest_score),cfg.WHITE,font,540,24)#----FPSshowText(screen,'FPS:'+str(int(clock.get_fps())),cfg.RED,font,8,8)#--显示剩余生命值showLife(screen,myaircraft.num_life,cfg.GREEN)pygame.display.update()clock.tick(cfg.FPS)withopen('score','w')asf:f.write(str(highest_score))returnis_win'''主函数'''defmain():#初始化pygame.init()pygame.display.set_caption('外星人入侵——九歌')screen=pygame.display.set_mode(cfg.SCREENSIZE)pygame.mixer.init()pygame.mixer.music.load(cfg.BGMPATH)pygame.mixer.music.set_volume(0.4)pygame.mixer.music.play(-1)whileTrue:is_win=startGame(screen)endInterface(screen,cfg.BLACK,is_win)'''run'''if__name__=='__main__':main()
13、井字棋888
玩法:我打赌大家在课堂上肯定玩过这个,想想当年和同桌玩这个废了好几本本子。
源码分享
fromtkinterimport*importtkinter.messageboxasmsgroot=Tk()root.title('TIC-TAC-TOE---ProjectGurukul')#labelsLabel(root,text="player1:X",font="times15").grid(row=0,column=1)Label(root,text="player2:O",font="times15").grid(row=0,column=2)digits=[1,2,3,4,5,6,7,8,9]#forplayer1sign=Xandforplayer2sign=Ymark=''#countingtheno.ofclickcount=0panels=["panel"]*10defwin(panels,sign):return((panels[1]==panels[2]==panels[3]==sign)or(panels[1]==panels[4]==panels[7]==sign)or(panels[1]==panels[5]==panels[9]==sign)or(panels[2]==panels[5]==panels[8]==sign)or(panels[3]==panels[6]==panels[9]==sign)or(panels[3]==panels[5]==panels[7]==sign)or(panels[4]==panels[5]==panels[6]==sign)or(panels[7]==panels[8]==panels[9]==sign))defchecker(digit):globalcount,mark,digits#Checkwhichbuttonclickedifdigit==1anddigitindigits:digits.remove(digit)##player1willplayifthevalueofcountisevenandforoddplayer2willplayifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton1.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==2anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton2.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==3anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton3.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==4anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton4.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==5anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton5.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==6anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton6.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==7anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton7.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==8anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton8.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()ifdigit==9anddigitindigits:digits.remove(digit)ifcount%2==0:mark='X'panels[digit]=markelifcount%2!=0:mark='O'panels[digit]=markbutton9.config(text=mark)count=count+1sign=markif(win(panels,sign)andsign=='X'):msg.showinfo("Result","Player1wins")root.destroy()elif(win(panels,sign)andsign=='O'):msg.showinfo("Result","Player2wins")root.destroy()###ifcountisgreaterthen8thenthematchhasbeentiedif(count>8andwin(panels,'X')==Falseandwin(panels,'O')==False):msg.showinfo("Result","MatchTied")root.destroy()####definebuttonsbutton1=Button(root,width=15,font=('Times16bold'),height=7,command=lambda:checker(1))button1.grid(row=1,column=1)button2=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(2))button2.grid(row=1,column=2)button3=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(3))button3.grid(row=1,column=3)button4=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(4))button4.grid(row=2,column=1)button5=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(5))button5.grid(row=2,column=2)button6=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(6))button6.grid(row=2,column=3)button7=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(7))button7.grid(row=3,column=1)button8=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(8))button8.grid(row=3,column=2)button9=Button(root,width=15,height=7,font=('Times16bold'),command=lambda:checker(9))button9.grid(row=3,column=3)root.mainloop()
万水千山总是情,点个行不行。
推荐阅读厉害了,用Python绘制动态可视化图表,并保存成gif格式2022-02-21 【干货分享】推荐6个好用到爆的Pycharm插件2022-02-16 【干货分享】推荐5个可以让你事半功倍的Python自动化脚本2022-02-14 没有50W彩礼 女友被强行拽走! Python数据分析全国各地的彩礼情况,细谈结一次婚到底要多少钱2022-02-13 用Python绘制谷爱凌的卡通动漫形象,太惊艳了2022-02-10 推荐10个好用到爆的Jupyter Notebook插件2022-01-30