最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python實(shí)現(xiàn)高配版王者小游戲

 更新時(shí)間:2023年03月16日 09:30:13   作者:十九1919  
咳咳,又是一款新的小游戲,就是大家熟悉的王者~本文將利用python來(lái)實(shí)現(xiàn)高(di)配版的王者的小游戲,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

前言

咳咳,又是一款新的小游戲,就是大家熟悉的王者~

來(lái)看我用python來(lái)實(shí)現(xiàn)高(di)配版的王者

是一款拿到代碼運(yùn)行后,可直接玩的游戲,是摸魚(yú)必備的小游戲
小聲說(shuō),我玩了一下午…

好了,先給你們看看效果吧,技術(shù)就這么多將就看看吧 

效果展示

必備素材

主要代碼

導(dǎo)入模塊

import pygame
import os.path
import csv
import setting as set
import live
import game_event
import gameui as gi
import startupui as si

程序主函數(shù)

def run_game():
    #初始化pygame庫(kù)
    pygame.init()
    #創(chuàng)建時(shí)鐘對(duì)象(控制幀率)
    clock=pygame.time.Clock()
    #實(shí)例化設(shè)置類,用于導(dǎo)入游戲設(shè)置
    setting=set.Setting()
    #設(shè)置游戲窗口
    screen=pygame.display.set_mode((setting.screen_width,setting.screen_height))
    pygame.display.set_caption(setting.screen_caption)

設(shè)置不同的組,用于分別處理各種物品間的關(guān)系

#玩家組
group_player=pygame.sprite.Group()
#玩家的攻擊組
group_attack=pygame.sprite.Group()
#敵人組
group_enemy=pygame.sprite.Group()
#敵人的攻擊組
group_enemy_attack=pygame.sprite.Group()

實(shí)例化ui對(duì)象

    #showinfo用于在游戲內(nèi)顯示人物血條等信息
    showinfo=gi.Info(setting,screen)
    #人物選擇按鈕
    yi_button=si.MonkeyKingButton(screen,setting)
    monkey_button=si.YiButton(screen,setting)
    fox_button=si.FoxButton(screen,setting)
    bin_button=si.BinButton(screen,setting)

游戲開(kāi)始界面的按鈕

    pve_button=si.PVEButton(screen,setting)
    pvp_button=si.PVPButton(screen,setting)
    endless_button=si.EndlessButton(screen,setting)
    control_button=si.ControlButton(screen,setting)
    memory_button=si.RecordButton(screen,setting)
    cooling_button=si.CoolingButton(screen,setting)

游戲背景

    select_button=si.SelectButton(screen,setting)
    win_button=si.WinButton(screen,setting)
    dead_button=si.DeadButton(screen,setting)

玩家當(dāng)前選擇的人物標(biāo)記

    player_button_1=si.PlayerButton1(screen,setting)
    player_button_2=si.PlayerButton2(screen,setting)
    #空白按鈕
    none_button=si.NoneButton(screen,setting)
    #空白圖像
    none_info=gi.ExInfo(screen,none_button,setting.introduce_none)

介紹按鈕作用的圖像

    pve_info=gi.ExInfo(screen,pve_button,setting.introduce_pve)
    pvp_info=gi.ExInfo(screen,pvp_button,setting.introduce_pvp)
    endless_info=gi.ExInfo(screen,endless_button,setting.introduce_endless)
    control_info=gi.ExInfo(screen,control_button,setting.introduce_control)
    record_info=gi.ExInfo(screen,memory_button,setting.introduce_record)
    cooling_info=gi.ExInfo(screen,cooling_button,setting.introduce_cooling)

按鈕組(繪制時(shí),在前的按鈕會(huì)被在后的按鈕覆蓋)

    buttons=[select_button,yi_button,monkey_button,fox_button,bin_button,
             pve_button,pvp_button,endless_button,
             cooling_button,control_button,memory_button,
             dead_button,win_button]

標(biāo)簽按鈕組

    choose_buttons=[player_button_1,player_button_2]

介紹按鈕作用的圖像組

    button_info_dict={none_button:none_info,pve_button:pve_info,pvp_button:pvp_info,
                      endless_button:endless_info,control_button:control_info,
                      memory_button:record_info,cooling_button:cooling_info}
    #當(dāng)前顯示的圖像列表
    info_label=[]
    #存儲(chǔ)模擬剛體運(yùn)動(dòng)的列表
    rigidbody_list=[]
    #玩家實(shí)例,初始化為戰(zhàn)士
    player_1=live.MonkeyKing(setting,screen)
    player_2=live.MonkeyKing(setting,screen)

    if not os.path.exists(setting.record_path):
        #如果游戲記錄文件不存在就新創(chuàng)建一個(gè)
        with open(setting.record_path,'w',newline="") as f:
            writer=csv.writer(f)
            header=["Time","Mode","Winner","1st Score","2st Score","Duration(s)","1st Player","2nd Player","isCooling"]
            writer.writerow(header)  

游戲主循環(huán)

    while True: 
        #繪制背景
        screen.blit(setting.screen_surface_background,(0,0))
        #設(shè)置游戲幀率
        clock.tick(setting.fps)
        #檢測(cè)鍵盤鼠標(biāo)事件   
        game_event.check_event(setting,screen,group_player,group_attack,group_enemy,
                               group_enemy_attack,buttons,showinfo,button_info_dict,info_label)

更新當(dāng)前選擇人物的標(biāo)簽

        game_event.update_choose(setting,buttons,choose_buttons)

游戲運(yùn)行,非玩家對(duì)抗模式

        if (setting.game_active and (setting.game_mode==0 or setting.game_mode==2)):

人物初始化

            if(not setting.isinit):
                if setting.player_1!=None:
                    player_1=setting.player_1
                    group_player.add(player_1)
                if setting.player_2!=None:
                    player_2=setting.player_2
                    group_player.add(player_2)                
                setting.isinit=True
            #游戲計(jì)時(shí)器
            setting.timer+=1
            #更新玩家
            group_player.update()
            #生成敵人
            game_event.generate_enemies(setting,group_enemy,screen) 

更新敵人,玩家的攻擊,敵人的攻擊,玩家狀態(tài)等

game_event.update_enemies(setting,showinfo,screen,group_player,group_enemy,group_attack,group_enemy_attack)
            game_event.update_attacks(setting,screen,group_attack,group_enemy,rigidbody_list)
            game_event.update_enemy_attacks(setting,screen,group_player,group_enemy_attack,rigidbody_list)
            game_event.update_state(setting,showinfo)
            game_event.update_rigidbody(setting,rigidbody_list)

勝利條件

            if setting.timer>=60*setting.fps and not group_enemy.spritedict and setting.game_mode==0:
                game_event.game_win(setting,showinfo,group_enemy,group_attack,group_enemy_attack)
                setting.timer=0

失敗條件

            if setting.isinit and ((setting.player_1!=None and setting.health_1<=0) or (setting.player_2!=None and setting.health_2<=0)):              
                game_event.game_dead(setting,showinfo,group_enemy,group_attack,group_enemy_attack)
                setting.timer=0

玩家對(duì)抗模式

        elif setting.game_active and setting.game_mode==1:

人物初始化

            if(not setting.isinit):
                if setting.player_1!=None and setting.player_2!=None:
                    player_1=setting.player_1
                    group_player.add(player_1)
                    player_2=setting.player_2
                    group_player.add(player_2)                        
                    setting.isinit=True

游戲計(jì)時(shí)器

setting.timer+=1

更新玩家

            player_1.update()
            player_2.update()

更新玩家的攻擊,信息顯示和物理模擬

game_event.update_attacks_pvp(setting,screen,group_attack,rigidbody_list)
            game_event.update_state(setting,showinfo)
            game_event.update_rigidbody(setting,rigidbody_list)

玩家1勝利條件

            if setting.isinit and setting.health_2<=0:
                setting.score_1+=1
                game_event.game_win(setting,showinfo,group_enemy,group_attack,group_enemy_attack)
                setting.timer=0

玩家2勝利條件

            if setting.isinit and setting.health_1<=0:
                setting.score_2+=1
                game_event.game_win(setting,showinfo,group_enemy,group_attack,group_enemy_attack)
                setting.timer=0

根據(jù)上述更新的結(jié)果繪制整個(gè)游戲窗口

        game_event.update_screen(setting,screen,group_player,group_attack,group_enemy,group_enemy_attack,
                                 showinfo,buttons,info_label,choose_buttons)                 

#運(yùn)行游戲
run_game()

以上就是基于Python實(shí)現(xiàn)高配版王者小游戲的詳細(xì)內(nèi)容,更多關(guān)于Python王者小游戲的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python 函數(shù)的詳解與應(yīng)用范例

    python 函數(shù)的詳解與應(yīng)用范例

    函數(shù)是組織好的,可重復(fù)使用的,用來(lái)實(shí)現(xiàn)單一,或相關(guān)聯(lián)功能的代碼段。函數(shù)能提高應(yīng)用的模塊性,和代碼的重復(fù)利用率。你已經(jīng)知道Python提供了許多內(nèi)建函數(shù),比如print()。但你也可以自己創(chuàng)建函數(shù),這被叫做用戶自定義函數(shù)
    2021-11-11
  • 關(guān)于Word2Vec可視化展示

    關(guān)于Word2Vec可視化展示

    這篇文章主要介紹了關(guān)于Word2Vec可視化展示,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Django中反向生成models.py的實(shí)例講解

    Django中反向生成models.py的實(shí)例講解

    今天小編就為大家分享一篇Django中反向生成models.py的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • 通過(guò)Python實(shí)現(xiàn)對(duì)SQL Server 數(shù)據(jù)文件大小的監(jiān)控告警功能

    通過(guò)Python實(shí)現(xiàn)對(duì)SQL Server 數(shù)據(jù)文件大小的監(jiān)控告警功能

    這篇文章主要介紹了通過(guò)Python實(shí)現(xiàn)對(duì)SQL Server 數(shù)據(jù)文件大小的監(jiān)控告警,本文給大家分享問(wèn)題報(bào)錯(cuò)信息及解決方案,需要的朋友可以參考下
    2021-04-04
  • PyQt5超詳細(xì)入門級(jí)教程(推薦!)

    PyQt5超詳細(xì)入門級(jí)教程(推薦!)

    PyQt5是Python編程語(yǔ)言的一個(gè)模塊,它提供了一種在Python中使用Qt庫(kù)的方式,下面這篇文章主要給大家介紹了關(guān)于PyQt5超詳細(xì)入門級(jí)教程的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-09-09
  • python實(shí)現(xiàn)名片管理系統(tǒng)

    python實(shí)現(xiàn)名片管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)名片管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • windows下安裝python paramiko模塊的代碼

    windows下安裝python paramiko模塊的代碼

    windows下安裝python paramiko模塊,有需要的朋友可以參考下
    2013-02-02
  • Python基于BeautifulSoup爬取京東商品信息

    Python基于BeautifulSoup爬取京東商品信息

    這篇文章主要介紹了Python基于BeautifulSoup爬取京東商品信息,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • python使用post提交數(shù)據(jù)到遠(yuǎn)程url的方法

    python使用post提交數(shù)據(jù)到遠(yuǎn)程url的方法

    這篇文章主要介紹了python使用post提交數(shù)據(jù)到遠(yuǎn)程url的方法,涉及Python使用post傳遞數(shù)據(jù)的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • Python處理Excel文件實(shí)例代碼

    Python處理Excel文件實(shí)例代碼

    本篇文章主要介紹了Python處理Excel文件實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-06-06

最新評(píng)論

宜兴市| 西盟| 京山县| 郎溪县| 乐安县| 庆云县| 襄樊市| 庆云县| 嘉义市| 永寿县| 蒙山县| 石首市| 香港 | 犍为县| 思南县| 墨脱县| 仙桃市| 延安市| 栾川县| 江津市| 黎城县| 绍兴县| 资中县| 海口市| 广河县| 五常市| 漳州市| 遂宁市| 布尔津县| 芒康县| 德化县| 海伦市| 呼伦贝尔市| 资阳市| 神农架林区| 安丘市| 林口县| 建水县| 吉首市| 葵青区| 岳西县|