import easygui,random player = 101 bad = 10 time = 0 room=[] killroom=[] for i in range(1,102): room.append(i) easygui.msgbox("欢迎来到屠夫躲猫猫,游戏规则:\n1,游戏开始时,有101名玩家,101个房间,还有10个屠夫。\n2,每一回合,你都要躲进一个房间,10个屠夫也会分别毁坏一个房间。\n3,如果你所在的房间被毁坏了,那么你就死了。\n4,如果你所在的房间没有被毁坏,那么你就可以进入下一个回合,幸存者只有一个!","说明") while True: while True: time+=1 hideROOM = easygui.enterbox("请输入房间号:","输入") if int(hideROOM) in room: easygui.msgbox("已躲藏。","躲藏") break elif int(hideROOM) not in room: easygui.msgbox("房间不存在。","警告") elif int(hideROOM) == None: easygui.msgbox("请选择房间!","警告") hideROOM = int(hideROOM) easygui.msgbox("屠夫来了!","警告") easygui.msgbox("“毁灭时间到!”","屠夫:") for i in range(1,11): kill = random.choice(room) killroom.append(kill) room.remove(kill) kill = 0 player-=10 easygui.msgbox("“哈哈哈哈哈哈哈哈哈哈!!!”","屠夫:") easygui.msgbox("屠夫走了。","警告") easygui.msgbox("屠夫毁坏了"+str(killroom)+"号房间,\n有"+str(len(killroom))+"个人死了,\n还剩下"+str(player)+"个玩家,\n"+str(len(room))+"个房间","报告") if hideROOM in killroom: flag = True easygui.msgbox("你死了!","死亡") easygui.msgbox("等待游戏结束……","等待") easygui.msgbox("幸存者所在的房间是:"+str(random.choice(room)),"幸存") break if time == 10: if flag == False: easygui.msgbox("恭喜你!你是幸存者!","幸存") break elif hideROOM not in killroom: easygui.msgbox("屠夫没毁坏你所在房间,即将进入下一回合。","存活")killroom = []
以上代码只能在python3.8运行(涉及到easygui)
文章内容属作者个人观点,不代表本站立场,如有侵权立删。