您的位置:首页 >聚焦 >

Python实现一个羊人杀小游戏,祝愿看到文章的小伙伴都不是小羊人

2022-12-17 19:48:05    来源:程序员客栈
Python实现一个羊人杀小游戏,祝愿看到文章的小伙伴都不是小羊人前言

halo,包子们下午好

最近疫情越来越严重了,很多小伙伴现在应该都是小羊人了吧

不要慌,小编的这个文章是经过消毒处理的,所以大家不要担心


【资料图】

今天给大家带来的是一个 羊人杀

说实话操作起来还是有那么一点点的难度的,但是大家不用担心

作为一个宠粉狂魔的小编,肯定都给大家准备好了的

直接上才艺

相关文件

关注小编,私信小编领取哟!

当然别忘了一件三连哟~~

公众号:Python日志

源码领取QQ群:494958217

开发工具

Python版本:3.7.8

相关模块:

random模块;

json模块;

time模块;

以及一些python自带的模块。

效果展示我是一个小羊人

我们的代号是 0 获得胜利的话就要去感染1 2 3 号小伙伴

任务

任务就是感染那些不是阳性小伙伴

代码展示

导入模块

from random import randint, choicefrom time import sleepimport json

介绍

print("4个好朋友一起混管,然后羊了,白天大家投票选出小羊人,选择把他拉走隔离!!")print("欢迎来到羊人杀!")try:    fs = open("shengli.dat")    fs.close()except FileNotFoundError:    lll = {"l": 0,      "p": 0,      "114514": 0,      "all": 0,      "jsfs": 0,      "ch": [],      "yy": 0      }    with open("shengli.dat", "w") as f_obj:        json.dump(lll, f_obj)else:    with open("shengli.dat") as f_obj:        lll = json.load(f_obj)print("小羊人胜场:", lll["l"])print("阴性胜场:", lll["p"])print("你死的次数:", lll["114514"])print("总场次:", lll["all"])print("识破的小羊人人数量:", lll["yy"])

电脑玩家名字随机

if len(lll["ch"]) != 0:    print("称号:" + ",".join(lll["ch"]))sleep(0.3)a = ["阴性 ", "阴性", "小羊人", "女巫"]  # 身份,用列表表示(用元组也行)xing = ("王", "李", "张", "刘", "徐", "冯", "袁", "邓", "韩", "杜", "朴", "金", "逄")zhongjian = ("既", "海", "若", "树", "丽", "虎", "涵")zuihou = ("羽", "生", "茵", "芹", "乔", "智", "丽")disi = ("玺", "霍", "获", "岚", "吾", "乐", "空", "阵")p1 = choice(xing) + choice(zhongjian)p2 = choice(xing) + choice(zhongjian) + choice(zuihou)p3 = choice(xing) + choice(zhongjian) + choice(zuihou) + choice(disi)

开始游戏

wanjianame = [p1, p2, p3]pl = ["0", "1", "2", "3"]  # 玩家player0 = choice(a)  # 设置玩家身份ar = a.index(player0)print("等待玩家进入游戏中...")sleep(randint(0, 3))print("玩家1" + "(" + p1 + ")加入游戏")sleep(randint(0, 3))print("玩家2" + "(" + p2 + ")加入游戏")sleep(randint(0, 3))print("玩家3" + "(" + p3 + ")加入游戏")print("玩家已全齐,开始游戏倒计时")timer = 3for i in range(3):    print(timer, end=" ")    timer -= 1  sleep(1)player1 = choice(a)ae = a.index(player1)player2 = choice(a)ac = a.index(player2)player3 = choice(a)ad = a.index(player3)while ae == ar or ae == ac or ae == ad or ad == ac or ad == ar or ac == ar:    player1 = choice(a)    ae = a.index(player1)    player2 = choice(a)    ac = a.index(player2)    player3 = choice(a)    ad = a.index(player3)ap = [player0, player1, player2, player3]langren = ap.index("小羊人")nvwu = ap.index("女巫")print("\n你的身份是" + player0)nvwuhuozhe = Truenvwuyouduyao = Truenvwujiuming = Truedays = 0

总结

因为代码量稍微有一点点大,所以就没有全部都放在这里给大家展示

如果有小伙伴需要源码的可以看下方联系方式哈

源码领取

【领取方式】

QQ扫码添加

【依次发放,请勿重复添加】

添加时备注“公众号”

即可免费领取学习资料和课程

或者直接搜索QQ群:494958217 领取

Python日志资料领取加群QQ群:494958217

关键词: 开始游戏 准备好了

相关阅读