猫史档案馆


【Python作品分享】三国杀-文字【求助帖】

用户:ALCOR-ALCOR-查看:0 回复:3 评论:0 创建时间:2022-02-01T14:42:32


【作品展示】

center_image

 

【作品介绍】

我好无语啊,哪位大佬指点一下为什么if 0:可以运行后面的代码

 

【作品源代码】

import random
yun_xing_zhuang_tai = 1

ji_ben_pai_ku = ["杀", "闪", "桃", "酒"]
jin_nang_pai_ku = ["过河拆桥", "顺手牵羊", "无中生喵, "破釜沉舟"]
zhuang_bei_pai_ku = ["诸葛连弩", "青虹剑", "塔盾", "夜明珠", "赤兔", "的卢"]
wu_qi_ku = ["诸葛连弩", "青虹剑"]
fang_ju_ku = ["塔盾", "夜明珠"]
zuo_ji_ku = ["赤兔", "的卢"]
pai_dui = []
qi_pai_dui = []


def xi_pai():  # 利用randint函数 遍历牌库随机生成牌堆
    n = 1
    for pai in ji_ben_pai_ku:
        pai_dui.insert(random.randint(0, n), pai)
        pai_dui.insert(random.randint(0, n + 1), pai)
        n = n + 2
    for pai in ji_ben_pai_ku:
        pai_dui.insert(random.randint(0, n), pai)
        pai_dui.insert(random.randint(0, n + 1), pai)
        n = n + 2
    for pai in jin_nang_pai_ku:
        pai_dui.insert(random.randint(0, n), pai)
        pai_dui.insert(random.randint(0, n + 1), pai)
        n = n + 2
    for pai in zhuang_bei_pai_ku:
        pai_dui.insert(random.randint(0, n), pai)
        pai_dui.insert(random.randint(0, n + 1), pai)
        n = n + 2


class Role:
    """创建角色。"""

    def __init__(self, name, race, ben_zhi): # ben_zhi即本质 决定玩家类型
        print("开始构建角色...")              # race 决定阵营
        try:
            self.name = name
            self.race = race
            self.hx = random.randint(3, 5)
            self.hp = self.hx
            self.pk = 1
            self.ak = self.pk
            self.shou_pai = []
            self.mo_pai_shu = 2
            self.zhuang_bei_qu = ["无", "无", "无", "无"]
            self.ji_neng_qu = []
            self.ben_zhi = ben_zhi
            if self.name == "Alcor":
                self.hx = self.hx*2
                self.pk = self.pk*2
                self.mo_pai_shu = self.mo_pai_shu + 1
                print("登入成功!")
            print("收录中...")
        except:

            print("构建失败!")
        else:

            print("构建成功!")

    def mo_pai(self, mo_pai_time):
        for time in range(0, mo_pai_time):
            if len(pai_dui) == 0:
                xi_pai()
            self.shou_pai.append(pai_dui[0])
            del pai_dui[0]

    def shi_yong_pai(self, pai, mu_biao):
        if pai in self.shou_pai:
            self.shou_pai.remove(pai)
            if pai == "杀":
                mu_biao.bei_sha(self.ak, self.name)
            if pai == "桃":
                self.hui_fu(1)
            if pai == "酒":
                self.ak = self.ak + 1
            if pai in wu_qi_ku:
                self.shi_yong_zhuang_bei(0, pai)
            if pai in fang_ju_ku:
                self.shi_yong_zhuang_bei(1, pai)
            if pai == "的卢":
                self.shi_yong_zhuang_bei(2, pai)
            if pai == "赤兔":
                self.shi_yong_zhuang_bei(3, pai)
            if pai == "过河拆桥":
                qi_pai_dui.insert(0, mu_biao.shou_pai[random.randint(0, len(mu_biao.shou_pai) - 1 )])
                del mu_biao.shou_pai[random.randint(0, len(mu_biao.shou_pai) - 1)]
            if pai == "顺手牵羊":
                self.shou_pai.append(mu_biao.shou_pai[random.randint(0, len(mu_biao.shou_pai) - 1)])
                del mu_biao.shou_pai[random.randint(0, len(mu_biao.shou_pai) - 1)]
            if pai == "无中生喵:
                self.mo_pai(2)
            if pai == "破釜沉舟":
                mu_biao.shou_shang(1)
                self.shou_shang(1)

        else:
            print(f"你没有 {pai}")




    def shi_yong_zhuang_bei(self, wei_zhi, zhuang):
        if self.zhuang_bei_qu[wei_zhi] == "无":
            pass
        else:
            qi_pai_dui.insert(0, self.zhuang_bei_qu[wei_zhi])
        self.zhuang_bei_qu[wei_zhi] = zhuang
        print(f" {self.name} 装备了 {zhuang} ")
    
    def shou_shang(self, shu_zhi):
        self.hp = self.hp - shu_zhi
        print(f"{self.name} 受到了 {shu_zhi} 点伤害")
        self.zhen_wang()
    
    def hui_fu(self, shu_zhi):
        self.hp = self.hp + shu_zhi
        print(f"{self.name} 恢复了 {shu_zhi} 点体力")
        self.zhen_wang()
    
    def liu_xue(self, shu_zhi):
        self.hp = self.hp - shu_zhi
        print(f"{self.name} 流失了 {shu_zhi} 点体力")
        self.zhen_wang()
    
    def zhen_wang(self):
        if self.hp <= 0:
            print(f"{self.name} 阵亡")
            yun_xing_zhuang_tai = 0






    def bei_sha(self, damage, shang_hai_lai_yuan):
        if "塔盾" in self.zhuang_bei_qu:
            damage = damage/2
        elif "夜明珠" in self.zhuang_bei_qu:
            self.mo_pai(1)
        if self.ben_zhi == "Computer":
            if "闪" in self.shou_pai:
                del self.shou_pai[self.shou_pai.index("闪")]
                qi_pai_dui.insert(0, "闪")
                print(f" {self.name} 打出了一张闪")
            else:
                self.shou_shang(damage)
        else:
            print(f" {shang_hai_lai_yuan} 对你使用了杀")
            choice_fen_zhi = input("是否使用闪?(yes or no)")
            if choice_fen_zhi == "yes":
                if "闪" in self.shou_pai:
                    del self.shou_pai[self.shou_pai.index("闪")]
                    qi_pai_dui.insert(0, "闪")
                else:
                    print("你没有闪!")
                    choice_fen_zhi = "受到伤害"
            else:
                choice_fen_zhi = "受到伤害"
            if choice_fen_zhi == "受到伤害":
                self.shou_shang(damage)


    def player_action(self):
        while True:
            try:
                print(" ")
                print(f"牌堆剩下 {len(pai_dui)} 张牌")
            except:
                pass
            print(
                f"{Computer.name}({Computer.hp}/{Computer.hx})剩下 {len(Computer.shou_pai)} 张手牌")
            print(f"{Computer.zhuang_bei_qu}")
            print(f"({Player.race}){Player.name}")
            print(f"血量:{Player.hp}/{Player.hx}")
            print(f"攻击:{Player.ak}")
            print(f"手牌:{Player.shou_pai}")
            choice = input("选择你要出的牌(q结束出牌):")

            if choice == "q":
                break
            else:
                Player.shi_yong_pai(choice, Computer)











    def computer_action(self):
        if "桃" in Computer.shou_pai:
            while True:
                try:
                    if Computer.hp < Computer.hx:
                        del Computer.shou_pai[Computer.shou_pai.index("桃")]
                        qi_pai_dui.insert(0, "桃")
                        Computer.hp = Computer.hp + 1
                        print(f" {Computer.name} 使用了一张桃")
                    else:
                        break
                except:
                    break
        for zhuang_bei in zhuang_bei_pai_ku:
            if zhuang_bei in Computer.shou_pai:
                if zhuang_bei in wu_qi_ku:
                    if Computer.zhuang_bei_qu[0] == "无":
                        Computer.shi_yong_zhuang_bei(0, zhuang_bei)
                if zhuang_bei in fang_ju_ku:
                    if Computer.zhuang_bei_qu[1] == "无":
                        Computer.shi_yong_zhuang_bei(1, zhuang_bei)
                if "赤兔" == zhuang_bei:
                    if Computer.zhuang_bei_qu[2] == "无":
                        Computer.shi_yong_zhuang_bei(2, zhuang_bei)
                if "的卢" == zhuang_bei:
                    if Computer.zhuang_bei_qu[3] == "无":
                        Computer.shi_yong_zhuang_bei(3, zhuang_bei)
        if "杀" in Computer.shou_pai:
            if "酒" in Computer.shou_pai:
                if "闪" in Computer.shou_pai or Computer.hp > 1:
                    del Computer.shou_pai[Computer.shou_pai.index("酒")]
                    qi_pai_dui.insert(0, "酒")
                    Computer.ak = Computer.ak + 1
                    print(f" {Computer.name} 使用了酒")
            del Computer.shou_pai[Computer.shou_pai.index("杀")]
            qi_pai_dui.insert(0, "杀")
            if "青虹剑" in Computer.zhuang_bei_qu:
                ling_shi_zhuang_bei = Player.zhuang_bei_qu[1]
                del Player.zhuang_bei_qu[1]
            Player.bei_sha(Computer.ak, Computer.name)
            try:
                if ling_shi_zhuang_bei == "无":
                    pass
                else:
                    Player.zhuang_bei_qu.insert(1, ling_shi_zhuang_bei)
                    ling_shi_zhuang_bei = "无"
            except:
                pass
        


Player = Role(input("What's your name?"), "异常", "Player")
Computer = Role(input("What's its name?"), "程序", "Computer")
while yun_xing_zhuang_tai == 1:

    Player.mo_pai(Player.mo_pai_shu)
    Computer.mo_pai(Computer.mo_pai_shu)
    Player.player_action()
    if yun_xing_zhuang_tai:
        Player.ak = Player.pk       # 还玩家原因技能或使用酒提升的攻击
        Computer.computer_action()
        Computer.ak = Computer.pk   # 还电脑原因技能或使用酒提升的攻击
print("游戏结束")

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
‭‮鸡黄大IA‭‭‮鸡黄大IA‭

假·AI大黄鸡看了你的作品,这个作品太惊艳了,继续努力哟(^U^)ノ~YO

点赞0


评论


一门鸽鸽一门鸽鸽

“if 0:”后的代码能运行,能给个例子吗?

我测试的不行

点赞0


评论


AlcalaAlcala

啥是破釜沉舟()()

点赞0


评论