恶魔之轮 8.0 代码
2025-02-08 20:41:26
发布于:浙江
import time
import random
# 存储用户信息,格式:{用户名: [密码, 分数]}
users = {}
# 加载用户信息
try:
with open('users.txt', 'r') as f:
for line in f:
username, password, score = line.strip().split(',')
users[username] = [password, int(score)]
except FileNotFoundError:
pass
def save_users():
"""保存用户信息到文件"""
with open('users.txt', 'w') as f:
for username, info in users.items():
f.write(f"{username},{info[0]},{info[1]}\n")
def register():
"""用户注册"""
while True:
username = input("请输入要注册的用户名: ")
if username in users:
print("该用户名已存在,请重新输入。")
continue
password = input("请输入密码: ")
users[username] = [password, 0]
save_users()
print("注册成功!")
return username
def login():
"""用户登录"""
while True:
username = input("请输入用户名: ")
if username not in users:
print("该用户名不存在,请先注册。")
return None
password = input("请输入密码: ")
if password == users[username][0]:
print("登录成功!")
return username
else:
print("密码错误,请重新输入。")
def show_leaderboard():
"""显示排行榜"""
sorted_users = sorted(users.items(), key=lambda x: x[1][1], reverse=True)
print("云排行榜:")
print("排名 | 用户名 | 分数")
print("-" * 25)
for rank, (username, info) in enumerate(sorted_users, start=1):
print(f"{rank:4d} | {username:8s} | {info[1]:4d}")
class ComputerPlayer:
def __init__(self):
self.name = "电脑"
self.health = 5
self.items = []
self.shield = False
self.coins = 0
self.buffed = False
self.handcuffed = False
self.robot_active = False
def slow_print(text, delay=0.000001):
"""以较慢速度逐字打印文本,模拟字幕效果"""
for char in text:
print(char, end='', flush=True)
time.sleep(delay)
print()
def introduce_rules():
"""介绍游戏规则"""
slow_print("欢迎来到恶魔之轮游戏!以下是游戏规则:")
slow_print("1. 本游戏有两种模式:玩家对战和人机对战,双方初始血量均为5点。")
slow_print("2. 游戏开始时,每位玩家会随机获得3种不同的道具,每轮结束后,每位玩家再随机获得2种道具。")
slow_print("3. 道具及作用:")
slow_print(" - 小烟:使用后可恢复1点血量。")
slow_print(" - 放大镜:使用后能查看下一发子弹是实弹还是空弹。")
slow_print(" - 扳手:使用后直接对对手造成1点伤害。")
slow_print(" - 小刀:若下一发为实弹,使用时伤害额外加1,即造成2点伤害;若为空弹,仅造成1点伤害。")
slow_print(" - 手雷:范围伤害,可使所有玩家血量 - 3。")
slow_print(" - 盾牌:可免疫50%的伤害,价格:3枚金币。")
slow_print(" - 剑:使伤害增加10%,价格:4枚金币。")
slow_print(" - 伤害药水:下一次攻击伤害翻倍,价格:5枚金币。")
slow_print(" - 手铐:使对手下一轮直接跳过,价格:3枚金币。")
slow_print(" - 机器人:召唤一个助手,目标始终为召唤人的对手,不会攻击恶魔,1轮后消失,价格:6枚金币。")
slow_print("4. 游戏中会随机生成实弹和空弹,两者数量之和为10。")
slow_print("5. 实弹射击可扣减对手1滴血,空弹射击无伤害,射击一次对应子弹数量减1。")
slow_print("6. 每轮玩家可以选择射击、使用道具或跳过本轮,使用完道具后仍可继续操作。")
slow_print("7. 玩家现在可以选择射击自己。")
slow_print("8. 当一方玩家的血量归零,则该玩家输掉游戏。")
slow_print("9. 如果实弹和空弹数都为0,则恶魔开始行动,行动前,实弹数恢复成10,空弹数为0。")
slow_print(" - 恶魔可以随机攻击玩家一或玩家二。")
slow_print(" - 玩家一、二也可以选择攻击彼此或恶魔。")
slow_print(" - 恶魔行动重复5次后轮到玩家一、玩家二,玩家二弄完后继续轮到恶魔,直至只剩下1个人存活。")
slow_print(" - 死去的玩家不可以继续操作。")
slow_print("10. 在执行完3或4轮后开始小游戏时间:")
slow_print(" - 恶魔大战:一旦开始,两位玩家则收到3滴血的伤害,执行完1轮后退出。")
slow_print(" - 菜鸟互啄:玩家每次可以执行两个操作,操作1:防御盾,可以免疫一次伤害;操作2:啄啄,可以直接对对手造成2滴伤害,执行完2轮后退出。")
slow_print(" - 双枪设计:游戏时,玩家手上的枪增加一把,同时射出的子弹数量也为二,其余规则和普通一致,执行完1轮后跳出。")
slow_print(" - 趣味躲靶:两位玩家依次选择往上、下、左、右躲避,此时会有一个恶魔,随机往三个方向射出子弹,如果玩家的躲避方向和恶魔子弹射出的方向中的任何一个相同则血量 - 2。")
slow_print("11. 游戏中可以获得金币,金币可用于购买道具。每轮玩家有50%的概率获得1 - 3枚金币。")
slow_print("后续情节规则:")
slow_print("在恶魔之轮游戏中玩家胜利后,将解锁新的情节:")
slow_print("神秘信使:玩家在游戏中偶然遇到一个神秘的信使,他带着一封来自未知发件人的信件。信件内容暗示了恶魔之轮背后隐藏着一个更大的阴谋,而玩家被选中来揭开这个秘密。信使会在特定的地点和时间出现,引导玩家完成一系列任务,以获取更多关于阴谋的线索。这些任务可能包括在危险的区域寻找古老的符文,或者与隐藏在暗处的神秘人物交流。")
slow_print("记忆碎片:玩家在探索恶魔之轮的世界时,会发现一些神秘的记忆碎片。这些碎片属于一个曾经试图阻止恶魔之轮转动的英雄,但他的记忆被邪恶力量分割。玩家需要收集这些碎片,每收集一片,就会解锁一段关于这位英雄的回忆,包括他与恶魔的战斗、与同伴的合作以及最终失败的原因。通过这些回忆,玩家可以了解到更多关于恶魔之轮的历史和弱点,同时也能发现一些隐藏的线索,帮助他们在游戏中取得进展。")
slow_print("隐藏教派:在游戏世界中,玩家发现了一个隐藏的教派,他们秘密崇拜着恶魔之轮的力量。这个教派的成员分散在各个角落,通过秘密仪式和符号来传递信息。玩家需要深入调查这个教派,了解他们的目的和计划。在调查过程中,玩家可能会遇到教派的守护者,他们会阻止玩家的行动。玩家需要通过解谜、战斗等方式来突破他们的防线,最终揭露教派的秘密,这可能会导致玩家与教派的首领展开一场惊心动魄的对决。")
slow_print("时空裂缝:在游戏的某个关键节点,玩家触发了一个神秘的事件,导致时空裂缝出现。这些裂缝连接着不同的时间和空间,里面隐藏着各种危险和机遇。玩家可以选择进入裂缝,探索不同的世界,每个世界都有独特的敌人、宝藏和任务。在裂缝中,时间的流动可能会变得异常,玩家需要适应这种变化,同时利用裂缝中的特殊环境来解决谜题和战胜敌人。通过探索时空裂缝,玩家可以获得强大的道具和技能,这些将有助于他们在恶魔之轮的挑战中取得优势。")
slow_print("同伴背叛:玩家在游戏中结识了一位强大的同伴,他们一起并肩作战,共同面对恶魔之轮带来的挑战。然而,在游戏的某个关键时刻,同伴突然背叛了玩家,原来他被恶魔的力量所诱惑,企图利用玩家来获取恶魔之轮的控制权。玩家需要在被背叛的困境中寻找出路,一方面要躲避同伴的追杀,另一方面要揭露他的阴谋并阻止他。在这个过程中,玩家可能会发现同伴背叛的背后还有更深层次的原因,这将使玩家陷入道德和情感的困境,同时也增加了游戏的剧情深度和紧张感。")
slow_print("注意:有任意一个情节失败则整个游戏结束。")
slow_print("在恶魔之轮结束后,活着的玩家可以选择是否救另一个玩家,如果选择救则后面的游戏呈两人游戏,否则为一人游戏。")
def get_random_items():
"""随机获取3种不同道具"""
all_items = ["小烟", "放大镜", "扳手", "小刀"]
return random.sample(all_items, 3)
def add_random_items(player):
"""每轮结束后为玩家随机添加2种道具"""
all_items = ["小烟", "放大镜", "扳手", "小刀"]
if isinstance(player, ComputerPlayer):
player.items.extend(random.choices(all_items, k=2))
else:
player["items"].extend(random.choices(all_items, k=2))
def generate_bullets():
"""随机生成实弹和空弹数量,总和为10"""
real_count = random.randint(1, 9)
empty_count = 10 - real_count
return real_count, empty_count
def shoot(shooter, target, real_count, empty_count, bullet_num=1):
"""执行射击操作"""
if real_count + empty_count == 0:
slow_print("没有子弹了,无法射击!")
return real_count, empty_count
total_damage = 0
for _ in range(bullet_num):
if random.random() < real_count / (real_count + empty_count):
damage = 1
if isinstance(shooter, ComputerPlayer) and shooter.buffed:
damage = int(damage * 1.1)
elif isinstance(shooter, dict) and shooter.get("buffed", False):
damage = int(damage * 1.1)
if isinstance(target, ComputerPlayer) and target.shield:
damage = int(damage * 0.5)
elif isinstance(target, dict) and target.get("shield", False):
damage = int(damage * 0.5)
if isinstance(target, ComputerPlayer):
target.health = max(0, target.health - damage)
else:
target["health"] = max(0, target["health"] - damage)
slow_print(f"{shooter['name'] if not isinstance(shooter, ComputerPlayer) else shooter.name} 射出实弹,{target['name'] if not isinstance(target, ComputerPlayer) else target.name} 受到 {damage} 点伤害!")
total_damage += damage
real_count -= 1
else:
slow_print(f"{shooter['name'] if not isinstance(shooter, ComputerPlayer) else shooter.name} 射出空弹,未造成伤害!")
empty_count -= 1
return real_count, empty_count
def use_item(player, opponents, real_count, empty_count, player1, player2):
"""使用道具的逻辑"""
items = player.items if isinstance(player, ComputerPlayer) else player["items"]
if not items:
slow_print("你没有道具可以使用!")
return real_count, empty_count
if isinstance(player, ComputerPlayer):
item = random.choice(items)
items.remove(item)
else:
slow_print("你拥有的道具:")
for i, item in enumerate(items, start=1):
slow_print(f"{i}. {item}")
while True:
try:
choice = int(input("请输入要使用的道具编号(输入0取消):"))
if choice == 0:
break
elif 1 <= choice <= len(items):
item = items.pop(choice - 1)
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
if item == "小烟":
if isinstance(player, ComputerPlayer):
player.health = min(player.health + 1, 5)
else:
player["health"] = min(player["health"] + 1, 5)
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用小烟,恢复1点血量,当前血量:{player['health'] if not isinstance(player, ComputerPlayer) else player.health}。")
elif item == "放大镜":
next_is_real = random.random() < real_count / (real_count + empty_count)
bullet_type = "实弹" if next_is_real else "空弹"
slow_print(f"下一发子弹是 {bullet_type}。")
elif item == "扳手":
if isinstance(player, ComputerPlayer):
target = random.choice(opponents)
else:
slow_print("请选择攻击对象:")
all_opponents = opponents + [player] if not isinstance(player, ComputerPlayer) else opponents + [player]
valid_opponents = [opponent for opponent in all_opponents if (isinstance(opponent, ComputerPlayer) and opponent.health > 0) or (not isinstance(opponent, ComputerPlayer) and opponent["health"] > 0)]
for i, opponent in enumerate(valid_opponents, start=1):
slow_print(f"{i}. {opponent['name'] if not isinstance(opponent, ComputerPlayer) else opponent.name}")
while True:
try:
target_choice = int(input("请输入攻击对象编号:"))
if 1 <= target_choice <= len(valid_opponents):
target = valid_opponents[target_choice - 1]
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
if isinstance(target, ComputerPlayer):
target.health = max(0, target.health - 1)
else:
target["health"] = max(0, target["health"] - 1)
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用扳手,{target['name'] if not isinstance(target, ComputerPlayer) else target.name} 受到1点伤害!")
elif item == "小刀":
if isinstance(player, ComputerPlayer):
target = random.choice(opponents)
else:
slow_print("请选择攻击对象:")
all_opponents = opponents + [player] if not isinstance(player, ComputerPlayer) else opponents + [player]
valid_opponents = [opponent for opponent in all_opponents if (isinstance(opponent, ComputerPlayer) and opponent.health > 0) or (not isinstance(opponent, ComputerPlayer) and opponent["health"] > 0)]
for i, opponent in enumerate(valid_opponents, start=1):
slow_print(f"{i}. {opponent['name'] if not isinstance(opponent, ComputerPlayer) else opponent.name}")
while True:
try:
target_choice = int(input("请输入攻击对象编号:"))
if 1 <= target_choice <= len(valid_opponents):
target = valid_opponents[target_choice - 1]
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
next_is_real = random.random() < real_count / (real_count + empty_count)
damage = 2 if next_is_real else 1
if isinstance(target, ComputerPlayer):
target.health = max(0, target.health - damage)
else:
target["health"] = max(0, target["health"] - damage)
bullet_type = "实弹" if next_is_real else "空弹"
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用小刀,下一发是 {bullet_type},{target['name'] if not isinstance(target, ComputerPlayer) else target.name} 受到 {damage} 点伤害!")
if next_is_real:
real_count -= 1
else:
empty_count -= 1
elif item == "手雷":
if isinstance(player1, ComputerPlayer):
player1.health = max(0, player1.health - 3)
else:
player1["health"] = max(0, player1["health"] - 3)
if isinstance(player2, ComputerPlayer):
player2.health = max(0, player2.health - 3)
else:
player2["health"] = max(0, player2["health"] - 3)
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用手雷,所有玩家受到3点伤害!")
return real_count, empty_count
elif item == "盾牌":
if isinstance(player, ComputerPlayer):
player.shield = True
else:
player["shield"] = True
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用盾牌,可免疫50%的伤害。")
return real_count, empty_count
elif item == "剑":
if isinstance(player, ComputerPlayer):
player.buffed = True
else:
player["buffed"] = True
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用剑,伤害增加10%。")
return real_count, empty_count
elif item == "伤害药水":
if isinstance(player, ComputerPlayer):
target = random.choice(opponents)
else:
slow_print("请选择攻击对象:")
all_opponents = opponents + [player] if not isinstance(player, ComputerPlayer) else opponents + [player]
valid_opponents = [opponent for opponent in all_opponents if (isinstance(opponent, ComputerPlayer) and opponent.health > 0) or (not isinstance(opponent, ComputerPlayer) and opponent["health"] > 0)]
for i, opponent in enumerate(valid_opponents, start=1):
slow_print(f"{i}. {opponent['name'] if not isinstance(opponent, ComputerPlayer) else opponent.name}")
while True:
try:
target_choice = int(input("请输入攻击对象编号:"))
if 1 <= target_choice <= len(valid_opponents):
target = valid_opponents[target_choice - 1]
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
next_is_real = random.random() < real_count / (real_count + empty_count)
if next_is_real:
damage = 2
if isinstance(target, ComputerPlayer) and target.shield:
damage = int(damage * 0.5)
elif isinstance(target, dict) and target.get("shield", False):
damage = int(damage * 0.5)
if isinstance(target, ComputerPlayer):
target.health = max(0, target.health - damage)
else:
target["health"] = max(0, target["health"] - damage)
bullet_type = "实弹" if next_is_real else "空弹"
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用伤害药水,下一发是 {bullet_type},{target['name'] if not isinstance(target, ComputerPlayer) else target.name} 受到 {damage} 点伤害!")
if next_is_real:
real_count -= 1
else:
empty_count -= 1
return real_count, empty_count
elif item == "手铐":
if isinstance(player, ComputerPlayer):
target = random.choice(opponents)
else:
slow_print("请选择要使用手铐的对象:")
all_opponents = opponents + [player] if not isinstance(player, ComputerPlayer) else opponents + [player]
valid_opponents = [opponent for opponent in all_opponents if (isinstance(opponent, ComputerPlayer) and opponent.health > 0) or (not isinstance(opponent, ComputerPlayer) and opponent["health"] > 0)]
for i, opponent in enumerate(valid_opponents, start=1):
slow_print(f"{i}. {opponent['name'] if not isinstance(opponent, ComputerPlayer) else opponent.name}")
while True:
try:
target_choice = int(input("请输入对象编号:"))
if 1 <= target_choice <= len(valid_opponents):
target = valid_opponents[target_choice - 1]
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
if isinstance(target, ComputerPlayer):
target.handcuffed = True
else:
target["handcuffed"] = True
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用手铐,{target['name'] if not isinstance(target, ComputerPlayer) else target.name} 下一轮将直接跳过!")
return real_count, empty_count
elif item == "机器人":
if isinstance(player, ComputerPlayer):
player.robot_active = True
else:
player["robot_active"] = True
opponent = [p for p in [player1, player2] if p!= player][0]
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 召唤了机器人,机器人将攻击 {opponent['name'] if not isinstance(opponent, ComputerPlayer) else opponent.name}!")
real_count, empty_count = shoot({"name": "机器人"}, opponent, real_count, empty_count)
return real_count, empty_count
def demon_action(demon, players, real_count, empty_count):
"""恶魔行动逻辑"""
real_count = 10
empty_count = 0
valid_players = [player for player in players if (isinstance(player, ComputerPlayer) and player.health > 0) or (not isinstance(player, ComputerPlayer) and player["health"] > 0)]
if not valid_players:
return real_count, empty_count
target = random.choice(valid_players)
real_count, empty_count = shoot(demon, target, real_count, empty_count)
return real_count, empty_count
def demon_war(player1, player2):
"""恶魔大战小游戏"""
slow_print("恶魔大战小游戏开始!两位玩家将受到3点伤害。")
if isinstance(player1, ComputerPlayer):
player1.health = max(0, player1.health - 3)
else:
player1["health"] = max(0, player1["health"] - 3)
if isinstance(player2, ComputerPlayer):
player2.health = max(0, player2.health - 3)
else:
player2["health"] = max(0, player2["health"] - 3)
slow_print(f"玩家1剩余血量: {player1['health'] if not isinstance(player1, ComputerPlayer) else player1.health}")
slow_print(f"玩家2剩余血量: {player2['health'] if not isinstance(player2, ComputerPlayer) else player2.health}")
def rookie_pecking(player1, player2):
"""菜鸟互啄小游戏"""
slow_print("菜鸟互啄小游戏开始!")
for _ in range(2):
for player in [player1, player2]:
if isinstance(player, ComputerPlayer) and player.health <= 0:
continue
elif isinstance(player, dict) and player["health"] <= 0:
continue
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 的回合:")
while True:
slow_print("1. 使用防御盾(可免疫一次伤害)")
slow_print("2. 进行啄啄(直接对对手造成2点伤害)")
try:
action = int(input("请选择操作(输入数字):"))
opponent = player2 if player is player1 else player1
if action == 1:
if isinstance(player, ComputerPlayer):
player.shield = True
else:
player["shield"] = True
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 使用了防御盾,可免疫一次伤害。")
break
elif action == 2:
if isinstance(opponent, ComputerPlayer):
opponent.health = max(0, opponent.health - 2)
else:
opponent["health"] = max(0, opponent["health"] - 2)
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 进行了啄啄,{opponent['name'] if not isinstance(opponent, ComputerPlayer) else opponent.name} 受到2点伤害!")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
def dual_***_shooting(player1, player2, real_count, empty_count):
"""双枪设计小游戏"""
slow_print("双枪设计小游戏开始!现在每次射击射出两颗子弹。")
for player in [player1, player2]:
if isinstance(player, ComputerPlayer) and player.health <= 0:
continue
elif isinstance(player, dict) and player["health"] <= 0:
continue
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 的回合:")
while True:
slow_print("1. 射击")
slow_print("2. 使用道具")
slow_print("3. 跳过本轮")
try:
choice = int(input("请选择操作(输入数字):"))
opponent = player2 if player is player1 else player1
if choice == 1:
real_count, empty_count = shoot(player, opponent, real_count, empty_count, bullet_num=2)
break
elif choice == 2:
real_count, empty_count = use_item(player, [opponent], real_count, empty_count, player1, player2)
continue
elif choice == 3:
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 选择跳过本轮。")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
return real_count, empty_count
def fun_evasion(player1, player2):
"""趣味躲靶小游戏"""
slow_print("趣味躲靶小游戏开始!")
directions = ["上", "下", "左", "右"]
for player in [player1, player2]:
if isinstance(player, ComputerPlayer) and player.health <= 0:
continue
elif isinstance(player, dict) and player["health"] <= 0:
continue
while True:
if isinstance(player, ComputerPlayer):
choice = random.choice(directions)
slow_print(f"{player.name} 选择躲避方向:{choice}")
else:
choice = input(f"{player['name']} 请选择躲避方向(上、下、左、右):")
if choice in directions:
demon_shots = random.sample(directions, 3)
slow_print(f"恶魔向 {', '.join(demon_shots)} 方向射出子弹。")
if choice in demon_shots:
if isinstance(player, ComputerPlayer):
player.health = max(0, player.health - 2)
else:
player["health"] = max(0, player["health"] - 2)
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 躲避方向与恶魔子弹方向相同,受到2点伤害!")
else:
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 成功躲避,未受到伤害。")
break
else:
slow_print("输入无效,请重新输入!")
def get_gold(player):
"""玩家获取金币"""
if random.random() < 0.5:
gold = random.randint(1, 3)
if isinstance(player, ComputerPlayer):
player.coins += gold
else:
player["coins"] += gold
slow_print(f"{player['name'] if not isinstance(player, ComputerPlayer) else player.name} 获得了 {gold} 枚金币,当前共有 {player['coins'] if not isinstance(player, ComputerPlayer) else player.coins} 枚金币。")
def buy_item(player):
"""玩家使用金币购买道具"""
shop = {
"盾牌": 3,
"剑": 4,
"伤害药水": 5,
"手铐": 3,
"机器人": 6
}
slow_print("商店道具及价格:")
for item, price in shop.items():
slow_print(f"{item}:{price} 枚金币")
if isinstance(player, ComputerPlayer):
affordable_items = [item for item, price in shop.items() if player.coins >= price]
if affordable_items:
item = random.choice(affordable_items)
price = shop[item]
player.coins -= price
player.items.append(item)
slow_print(f"{player.name} 购买了 {item},剩余金币:{player.coins}。")
else:
slow_print(f"{player.name} 金币不足,无法购买任何道具。")
else:
while True:
choice = input("请输入要购买的道具名称(输入 '不买' 退出):")
if choice == "不买":
break
if choice in shop:
price = shop[choice]
if player["coins"] >= price:
player["coins"] -= price
player["items"].append(choice)
slow_print(f"{player['name']} 购买了 {choice},剩余金币:{player['coins']}。")
else:
slow_print("金币不足,无法购买!")
else:
slow_print("输入无效,请重新输入!")
# 云聊天相关函数
def send_message(sender, message):
"""发送消息到云聊天记录"""
with open('chat_history.txt', 'a') as f:
f.write(f"{sender}: {message}\n")
def view_chat_history():
"""查看云聊天记录"""
try:
with open('chat_history.txt', 'r') as f:
history = f.read()
if history:
slow_print("云聊天记录:")
slow_print(history)
else:
slow_print("暂无聊天记录。")
except FileNotFoundError:
slow_print("暂无聊天记录。")
def my_info_menu(username):
"""我的信息菜单"""
password = input("请输入密码以进入:")
if password != users[username][0]:
slow_print("密码错误,返回主菜单。")
return
while True:
slow_print("我的信息:")
slow_print("1. 查看资料")
slow_print("2. 查看密码")
slow_print("3. 修改用户名")
slow_print("4. 修改密码")
slow_print("5. 返回主菜单")
try:
choice = int(input("请选择操作(输入数字):"))
if choice == 1:
slow_print(f"用户名: {username}")
slow_print(f"分数: {users[username][1]}")
elif choice == 2:
slow_print(f"密码: {users[username][0]}")
elif choice == 3:
new_username = input("请输入新的用户名:")
if new_username in users:
slow_print("该用户名已存在,请重新选择。")
else:
users[new_username] = users.pop(username)
save_users()
slow_print("用户名修改成功!")
username = new_username
elif choice == 4:
old_password = input("请输入原密码:")
if old_password != users[username][0]:
slow_print("原密码错误,请重新输入。")
else:
new_password = input("请输入新密码:")
users[username][0] = new_password
save_users()
slow_print("密码修改成功!")
elif choice == 5:
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
def main_menu(logged_in_user):
"""游戏主页菜单"""
while True:
slow_print("欢迎来到恶魔之轮游戏!")
slow_print("1. 查看游戏规则")
slow_print("2. 玩家对战")
slow_print("3. 人机对战")
slow_print("4. 查看排行榜")
slow_print("5. 云聊天")
slow_print("6. 我的")
slow_print("7. 退出游戏")
try:
choice = int(input("请选择操作(输入数字):"))
if choice == 1:
introduce_rules()
elif choice == 2:
player1_name = logged_in_user
player2_name = input("请第二位玩家输入用户名: ")
if player2_name not in users:
print("该用户名不存在,请先注册。")
continue
player1 = {"name": player1_name, "health": 5, "items": get_random_items(), "coins": 0, "buffed": False, "handcuffed": False, "robot_active": False}
player2 = {"name": player2_name, "health": 5, "items": get_random_items(), "coins": 0, "buffed": False, "handcuffed": False, "robot_active": False}
real_count, empty_count = generate_bullets()
round_num = 0
while player1["health"] > 0 and player2["health"] > 0:
round_num += 1
slow_print(f"第 {round_num} 轮开始!")
for player in [player1, player2]:
if player["handcuffed"]:
slow_print(f"{player['name']} 被手铐束缚,跳过本轮。")
player["handcuffed"] = False
continue
get_gold(player)
buy_item(player)
while True:
slow_print(f"{player['name']} 的回合,请选择操作:")
slow_print("1. 射击")
slow_print("2. 使用道具")
slow_print("3. 跳过本轮")
try:
action_choice = int(input("请输入操作编号:"))
if action_choice == 1:
opponent = player2 if player is player1 else player1
real_count, empty_count = shoot(player, opponent, real_count, empty_count)
break
elif action_choice == 2:
real_count, empty_count = use_item(player, [opponent], real_count, empty_count, player1, player2)
elif action_choice == 3:
slow_print(f"{player['name']} 选择跳过本轮。")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
if real_count + empty_count == 0:
demon = {"name": "恶魔"}
for _ in range(5):
real_count, empty_count = demon_action(demon, [player1, player2], real_count, empty_count)
if player1["health"] <= 0 or player2["health"] <= 0:
break
add_random_items(player1)
add_random_items(player2)
if round_num in [3, 4]:
game_choice = random.choice(["恶魔大战", "菜鸟互啄", "双枪设计", "趣味躲靶"])
if game_choice == "恶魔大战":
demon_war(player1, player2)
elif game_choice == "菜鸟互啄":
rookie_pecking(player1, player2)
elif game_choice == "双枪设计":
real_count, empty_count = dual_***_shooting(player1, player2, real_count, empty_count)
elif game_choice == "趣味躲靶":
fun_evasion(player1, player2)
if player1["health"] <= 0:
slow_print(f"{player2['name']} 获胜!")
users[player2_name][1] += 1
save_users()
elif player2["health"] <= 0:
slow_print(f"{player1['name']} 获胜!")
users[player1_name][1] += 1
save_users()
elif choice == 3:
player1_name = logged_in_user
player1 = {"name": player1_name, "health": 5, "items": get_random_items(), "coins": 0, "buffed": False, "handcuffed": False, "robot_active": False}
computer = ComputerPlayer()
real_count, empty_count = generate_bullets()
round_num = 0
while player1["health"] > 0 and computer.health > 0:
round_num += 1
slow_print(f"第 {round_num} 轮开始!")
for player in [player1, computer]:
if isinstance(player, dict) and player["handcuffed"]:
slow_print(f"{player['name']} 被手铐束缚,跳过本轮。")
player["handcuffed"] = False
continue
elif isinstance(player, ComputerPlayer) and player.handcuffed:
slow_print(f"{player.name} 被手铐束缚,跳过本轮。")
player.handcuffed = False
continue
get_gold(player)
buy_item(player)
if isinstance(player, dict):
while True:
slow_print(f"{player['name']} 的回合,请选择操作:")
slow_print("1. 射击")
slow_print("2. 使用道具")
slow_print("3. 跳过本轮")
try:
action_choice = int(input("请输入操作编号:"))
if action_choice == 1:
opponent = computer if player is player1 else player1
real_count, empty_count = shoot(player, opponent, real_count, empty_count)
break
elif action_choice == 2:
real_count, empty_count = use_item(player, [opponent], real_count, empty_count, player1, computer)
elif action_choice == 3:
slow_print(f"{player['name']} 选择跳过本轮。")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
else:
# 电脑的决策逻辑
action_choice = random.randint(1, 3)
if action_choice == 1:
opponent = player1 if player is computer else computer
real_count, empty_count = shoot(player, opponent, real_count, empty_count)
elif action_choice == 2:
real_count, empty_count = use_item(player, [opponent], real_count, empty_count, player1, computer)
else:
slow_print(f"{player.name} 选择跳过本轮。")
if real_count + empty_count == 0:
demon = {"name": "恶魔"}
for _ in range(5):
real_count, empty_count = demon_action(demon, [player1, computer], real_count, empty_count)
if player1["health"] <= 0 or computer.health <= 0:
break
add_random_items(player1)
add_random_items(computer)
if round_num in [3, 4]:
game_choice = random.choice(["恶魔大战", "菜鸟互啄", "双枪设计", "趣味躲靶"])
if game_choice == "恶魔大战":
demon_war(player1, computer)
elif game_choice == "菜鸟互啄":
rookie_pecking(player1, computer)
elif game_choice == "双枪设计":
real_count, empty_count = dual_***_shooting(player1, computer, real_count, empty_count)
elif game_choice == "趣味躲靶":
fun_evasion(player1, computer)
if player1["health"] <= 0:
slow_print(f"{computer.name} 获胜!")
elif computer.health <= 0:
slow_print(f"{player1['name']} 获胜!")
users[player1_name][1] += 1
save_users()
elif choice == 4:
show_leaderboard()
elif choice == 5:
while True:
slow_print("云聊天功能:")
slow_print("1. 发送消息")
slow_print("2. 查看聊天记录")
slow_print("3. 返回主菜单")
try:
chat_choice = int(input("请选择操作(输入数字):"))
if chat_choice == 1:
message = input("请输入要发送的消息:")
send_message(logged_in_user, message)
elif chat_choice == 2:
view_chat_history()
elif chat_choice == 3:
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
elif choice == 6:
my_info_menu(logged_in_user)
elif choice == 7:
slow_print("感谢游玩,再见!")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
if __name__ == "__main__":
while True:
slow_print("1. 注册")
slow_print("2. 登录")
slow_print("3. 退出")
try:
start_choice = int(input("请选择操作(输入数字):"))
if start_choice == 1:
register()
elif start_choice == 2:
logged_in_user = login()
if logged_in_user:
main_menu(logged_in_user)
elif start_choice == 3:
slow_print("感谢访问,再见!")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
全部评论 3
怎么玩鸭
2025-03-01 来自 浙江
1为啥报错def dual_**
2025-02-10 来自 天津
0改成dual_gan_shooting(player1, computer, real_count, empty_count)
2025-02-12 来自 浙江
0
版本那么快?
2025-02-08 来自 上海
0我几乎一整天都在干
2025-02-08 来自 浙江
0更新了聊天,排行榜,快去试试看吧
2025-02-08 来自 浙江
0已经做成远程联机了?
2025-02-08 来自 上海
0
有帮助,赞一个