请用python写一个有3个狼人、1个女巫、1个预言家、1个守卫、1个猎人、1个炸弹人、2个平民的狼人杀程序中文版
时间: 2023-06-11 22:06:03 浏览: 171
小程序游戏之狼人杀
好的,以下是一个简单的狼人杀程序:
```python
import random
# 角色列表
roles = ['狼人', '狼人', '狼人', '女巫', '预言家', '守卫', '猎人', '炸弹人', '平民', '平民']
# 玩家列表
players = []
# 游戏开始前,每个玩家的初始状态
class Player:
def __init__(self, role):
self.role = role
self.live = True
self.poison = False
self.protect = False
self.vote = None
self.killed = False
# 生成玩家列表
for role in roles:
players.append(Player(role))
# 游戏开始
while True:
# 狼人行动
print('狼人请行动')
for player in players:
if player.role == '狼人' and player.live:
# 随机选择一名玩家
target = random.choice([p for p in players if p.live and p.role != '狼人'])
target.live = False
print('狼人杀了', target.role)
# 女巫行动
print('女巫请行动')
for player in players:
if player.role == '女巫' and player.live:
# 是否使用解药
use_cure = input('是否要使用解药?(y/n)')
if use_cure == 'y':
# 解药救人
target = input('请选择要救的玩家:')
for p in players:
if p.role == target:
p.live = True
print('女巫救了', target)
# 是否使用毒药
use_poison = input('是否要使用毒药?(y/n)')
if use_poison == 'y':
# 使用毒药
target = input('请选择要杀的玩家:')
for p in players:
if p.role == target:
p.poison = True
print('女巫毒了', target)
# 平民行动
print('平民请行动')
# 平民无法行动
# 预言家行动
print('预言家请行动')
for player in players:
if player.role == '预言家' and player.live:
# 查验一名玩家身份
target = input('请选择要查验的玩家:')
for p in players:
if p.role == target:
print(target, '的身份是', p.role)
# 守卫行动
print('守卫请行动')
for player in players:
if player.role == '守卫' and player.live:
# 守卫守护一名玩家
target = input('请选择要守护的玩家:')
for p in players:
if p.role == target:
p.protect = True
print('守卫守护了', target)
# 猎人行动
print('猎人请行动')
for player in players:
if player.role == '猎人' and player.live and player.killed:
# 猎人是否开枪
use_gun = input('是否要使用猎枪?(y/n)')
if use_gun == 'y':
# 使用猎枪
target = input('请选择要杀的玩家:')
for p in players:
if p.role == target:
p.live = False
print('猎人开枪杀了', target)
# 炸弹人行动
print('炸弹人请行动')
for player in players:
if player.role == '炸弹人' and player.live and player.killed:
# 炸弹人是否引爆
use_bomb = input('是否要引爆炸弹?(y/n)')
if use_bomb == 'y':
# 引爆炸弹
for p in players:
if p != player and p.live:
p.live = False
print('炸弹人引爆了炸弹,炸死了', p.role)
# 检查游戏是否结束
wolf_count = 0
good_count = 0
for player in players:
if player.live and (player.role == '狼人' or player.poison):
wolf_count += 1
elif player.live and player.role != '狼人':
good_count += 1
if wolf_count == 0:
print('好人胜利')
break
elif wolf_count >= good_count:
print('狼人胜利')
break
# 进入投票环节
print('请各位玩家投票')
for player in players:
if player.live and player.vote is None:
# 玩家投票
target = input('请', player.role, '投票:')
for p in players:
if p.role == target:
p.vote += 1
# 统计投票结果
max_vote = 0
max_player = None
for player in players:
if player.live and player.vote > max_vote:
max_vote = player.vote
max_player = player
# 进行投票结果的处理
if max_player is not None:
max_player.live = False
print(max_player.role, '被投票出局')
else:
print('平局,没有人被投票出局')
# 清除投票结果
for player in players:
player.vote = 0
```
这是一个简单的狼人杀程序,可以根据需要进行修改和扩展。
阅读全文