狼人杀主持代码(不是我的,是同学的)

创作者:https://www.luogu.com.cn/user/404181 FFFfeiXJ 

import random
import time
import os
#print("请输入板子数据")
rpsw="我是主持人"
banzi=["平民","平民","平民","平民","狼人","狼人","狼人","狼王","预言家","女巫","猎人","守卫"]
playern=12
#随机发卡
random.shuffle(banzi)

#在认领角色时记录啥时候领完
visited=[0,0,0,0,0,0,0,0,0,0,0,0]
visiteds=0

#记录一些主动技能角色是谁
yuyanjia=0
nvwu=0
shouwei=0

while visiteds<playern:
    player=int(input("请输入您的玩家编号:"))
    if player==0:
       if rpsw==input("请确认管理员密码以查看当前角色的分配:"):
           print(banzi);
    elif player==-1:
        break
    else:
        player=player-1
        print("您的身份是 "+banzi[player])
        if visited[player]==0:
            visited[player]=1
            visiteds=visiteds+1
            if banzi[player]=="预言家":
                yuyanjia=player+1
            elif banzi[player]=="女巫":
                nvwu=player+1
            elif banzi[player]=="守卫":
                shouwei=player+1
    os.system("pause")
    os.system("cls")
    
#以下统计每个人是否趋势以及各阵营活人数
dead=[0,0,0,0,0,0,0,0,0,0,0,0]
huomin=4
huoshen=4
huolang=4

#以下记录女巫是否还有技能
witchsave=0
witchkill=0

#记录时间数据
days=0

print("请确认所有玩家均已得知自己的身份,并按下任意键开始游戏。")
os.system("pause")
os.system("cls")

def dai(plyr):
    global huomin
    global huoshen
    global huolang
    i=plyr
    daizoued=int(input(str(i+1)+"号玩家,请发动技能并带走另一名玩家:"))
    i=daizoued-1
    dead[i]=1
    if banzi[i]=="平民":
        huomin=huomin-1;
    elif banzi[i]=="狼人" or banzi[i]=="狼王":
        huolang=huolang-1
    else:
        huoshen=huoshen-1
        print(str(daizoued)+"号玩家,卒。")
    if banzi[i]=="狼王" or banzi[i]=="猎人":
        dai(i)
def die(plyr):
    global huomin
    global huoshen
    global huolang
    dead[plyr]=1
    print(str(plyr+1)+"号玩家,卒。")
    if banzi[plyr]=="平民":
        huomin=huomin-1;
    elif banzi[plyr]=="狼人" or banzi[plyr]=="狼王":
        huolang=huolang-1
    else:
        huoshen=huoshen-1
    
    if banzi[plyr]=="猎人" or banzi[plyr]=="狼王":
        dai(plyr)

while True:
    print("天黑请闭眼。")
    time.sleep(2)
    os.system("pause")

    wolfk=-1  #被刀的人
    saved=0   #女巫救了没
    witchk=-1 #被泼的人
    guarded=-1#被守的人
    
    os.system("cls")
    print("天黑请闭眼。\n")
    twolfk=input("狼人请睁眼,并选择你们要刀的玩家:")
    wolfk=int(twolfk)
    print("狼人请闭眼。")
    time.sleep(2)
    
    if dead[yuyanjia]==0:
        os.system("cls")
        print("天黑请闭眼。\n")
        yuyaned=int(input("预言家请睁眼,并选择你要查验的玩家:"))
        if banzi[yuyaned-1]=="狼人" or banzi[yuyaned-1]=="狼王":
            print("他的身份是:查杀。")
        else:
            print("他的身份是:金水。")
        print("预言家请闭眼。")
        time.sleep(2)

    if dead[nvwu]==0:
        os.system("cls")
        print("天黑请闭眼。\n")
        print("女巫请睁眼。")
        if witchsave==0:
            saveonot=int(input("今晚趋势的是"+twolfk+"号玩家。你是否要救Ta?(1为是,0为否)"))
            if saveonot==1:
                saved=1
                witchsave=1
        
        if witchkill==0 and saved==0:
            killonot=int(input("你是否要泼死一个玩家?(1为是,0为否)"))
            if killonot==1:
                witchkill=1
                twitchk=input("请选择你要泼死的玩家:")
                witchk=int(twitchk)
        print("女巫请闭眼。")
        time.sleep(2)

    if dead[shouwei]==0:
        days=days+1
        os.system("cls")
        print("天黑请闭眼。\n")
        guarded=int(input("守卫请睁眼,并选择你要守护的玩家:"))
        print("守卫请闭眼。")
        time.sleep(2)

    fangzhu=[0,0,0,0,0,0,0,0,0,0,0,0]
    
    os.system("cls")
    print("天亮了。\n")
    if (guarded==wolfk)^(saved)==1 and witchk==-1:
        print("今晚是个平安夜。")
    else:
        print("今晚的倒牌情况如下:")
    
    if saved==1 and guarded==wolfk:
        dead[wolfk-1]=1
        print(str(wolfk)+"号玩家,卒。")
        if banzi[wolfk-1]=="平民":
            huomin=huomin-1;
        elif banzi[wolfk-1]=="狼人" or banzi[wolfk-1]=="狼王":
            huolang=huolang-1
        else:
            huoshen=huoshen-1
    else:
        die(wolfk-1)
    
    if witchk!=-1:
        dead[witchk-1]=1
        print(str(witchk)+"号玩家,卒。")
        if banzi[witchk-1]=="平民":
            huomin=huomin-1;
        elif banzi[witchk-1]=="狼人" or banzi[witchk-1]=="狼王":
            huolang=huolang-1
        else:
            huoshen=huoshen-1
    
    for i in range(playern):
        if dead[i]==0:
            os.system("cls")
            print("请所有玩家按照顺序依次发言。\n请"+str(i+1)+"号玩家发言。发言完毕后,请按下任意键。")
            os.system("pause")
    print("\n接下来开始放逐投票。请依次输入你们需要放逐的玩家。若弃票,输入0。")
    for i in range(playern):
        if dead[i]==0:
            fangzhued=int(input("请"+str(i+1)+"号玩家投票:"))
            if fangzhued!=0:
                fangzhu[fangzhued-1]=fangzhu[fangzhued-1]+1
    maxpiao=0
    pingpiao=[0,0,0,0,0,0,0,0,0,0,0,0]
    pingpiaon=0
    for i in range(playern):
        maxpiao=max(maxpiao,fangzhu[i])
    for i in range(playern):
        if fangzhu[i]==maxpiao and dead[i]==0:
            pingpiao[i]=1
            pingpiaon=pingpiaon+1
    if pingpiaon!=1:
        for i in range(playern):
            if pingpiao[i]==1:
                os.system("cls")
                print("请"+str(i+1)+"号玩家进行平票狡辩。发言完毕后,请按下任意键。")
                os.system("pause")
    
        fangzhu=[0,0,0,0,0,0,0,0,0,0,0,0]

        print("重新开始放逐投票。请依次输入你们需要放逐的玩家。若弃票,输入0。")
        for i in range(playern):
            if dead[i]==0:
                fangzhued=int(input("请"+str(i+1)+"号玩家投票:"))
                if fangzhued!=0:
                    fangzhu[fangzhued-1]=fangzhu[fangzhued-1]+1
    
        maxpiao=0
        pingpiao=[0,0,0,0,0,0,0,0,0,0,0,0]
        pingpiaon=0
        for i in range(playern):
            maxpiao=max(maxpiao,fangzhu[i])
        for i in range(playern):
            if fangzhu[i]==maxpiao and dead[i]==0:
                pingpiao[i]=1
                pingpiaon=pingpiaon+1
        if pingpiaon!=1:
            print("由于仍然有平票,此次投票作废。游戏继续。")
        else:
            for i in range(playern):
                if pingpiao[i]==1:
                    print(str(i+1)+"号玩家被抬出。")
                    die(i)
                    time.sleep(2)
                    os.system("pause")
                    break
    else:
        for i in range(playern):
            if pingpiao[i]==1:
                print(str(i+1)+"号玩家被抬出。")
                die(i)
                time.sleep(2)
                os.system("pause")
                break
    if huoshen==0 or huomin==0:
        os.system("cls")
        print("游戏结束,狼人胜利。")
        break
    elif huolang==0:
        os.system("cls")
        print("游戏结束,好人胜利。")
        break
    else:
        print("游戏继续。")
        time.sleep(5)
        os.system("cls")
posted @ 2023-11-11 13:49  Anniw  阅读(253)  评论(0编辑  收藏  举报