恶魔之轮 9.0 版本
2025-02-09 11:38:37
发布于:浙江
import time
import random
import string
# 存储用户信息,格式:{用户ID: [用户名, 密码, 分数, 关注列表, 粉丝列表]}
users = {}
def generate_id():
return ''.join(random.choices(string.digits, k=10))
def save_users():
"""保存用户信息到文件"""
with open('users.txt', 'w') as f:
for user_id, info in users.items():
follow_list_str = '|'.join(info[3])
follower_list_str = '|'.join(info[4])
f.write(f"{user_id},{info[0]},{info[1]},{info[2]},{follow_list_str},{follower_list_str}\n")
def load_users():
global users
users = {}
try:
with open('users.txt', 'r') as f:
for line in f:
parts = line.strip().split(',')
user_id = parts[0]
username = parts[1]
password = parts[2]
score = int(parts[3])
follow_list = parts[4].split('|') if parts[4] else []
follower_list = parts[5].split('|') if parts[5] else []
users[user_id] = [username, password, score, follow_list, follower_list]
except FileNotFoundError:
pass
def register():
"""用户注册"""
while True:
print("1. 注册")
print("2. 忘记ID")
try:
sub_choice = int(input("请选择操作(输入数字):"))
if sub_choice == 1:
while True:
username = input("请输入要注册的用户名: ")
# 检查用户名是否已存在
if any(info[0] == username for info in users.values()):
print("该用户名已被使用,请选择其他用户名。")
else:
break
password = input("请输入密码: ")
user_id = generate_id()
# 这里将密码存储到用户信息中
users[user_id] = [username, password, 0, [], []]
save_users()
print(f"注册成功!您的ID为: {user_id}")
return user_id
elif sub_choice == 2:
username = input("请输入用户名: ")
password = input("请输入密码: ")
for user_id, info in users.items():
if info[0] == username and info[1] == password:
print(f"您的ID是: {user_id}")
break
else:
print("用户名或密码错误,未找到对应的ID。")
except ValueError:
print("输入无效,请输入数字!")
def login():
"""用户登录"""
while True:
user_id = input("请输入您的ID: ")
if user_id not in users:
print("该ID不存在,请先注册。")
return None
password = input("请输入密码: ")
if password == users[user_id][1]:
print("登录成功!")
return user_id
else:
print("密码错误,请重新输入。")
def show_leaderboard():
"""显示排行榜"""
sorted_users = sorted(users.items(), key=lambda x: x[1][2], reverse=True)
print("云排行榜:")
print("排名 | 用户ID | 用户名 | 分数")
print("-" * 40)
for rank, (user_id, info) in enumerate(sorted_users, start=1):
print(f"{rank:4d} | {user_id:10s} | {info[0]:8s} | {info[2]: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
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_id, receiver_id, message):
"""发送私聊消息"""
if receiver_id not in users:
slow_print("该用户ID不存在,请检查后重新输入。")
return
try:
with open(f'chat_{sender_id}_{receiver_id}.txt', 'a') as f:
f.write(f"{users[sender_id][0]}: {message}\n")
# 标记接收方有新消息
if not hasattr(users[receiver_id], 'new_messages'):
users[receiver_id].append(set())
users[receiver_id][-1].add(sender_id)
slow_print("消息发送成功!")
except Exception as e:
slow_print(f"消息发送失败:{e}")
def view_private_chat_history(sender_id, receiver_id):
"""查看私聊聊天记录"""
try:
with open(f'chat_{sender_id}_{receiver_id}.txt', 'r') as f:
history = f.read()
if history:
slow_print("私聊聊天记录:")
slow_print(history)
else:
slow_print("暂无聊天记录。")
# 标记该发送方的消息已查看
if hasattr(users[sender_id], 'new_messages') and receiver_id in users[sender_id][-1]:
users[sender_id][-1].remove(receiver_id)
except FileNotFoundError:
slow_print("暂无聊天记录。")
def follow_user(logged_in_id, target_id):
"""关注用户"""
if target_id not in users:
slow_print("该用户ID不存在,请检查后重新输入。")
return
if target_id in users[logged_in_id][3]:
slow_print("你已经关注了该用户。")
return
users[logged_in_id][3].append(target_id)
users[target_id][4].append(logged_in_id)
# 标记目标用户有新的关注者
if not hasattr(users[target_id], 'new_followers'):
users[target_id].append(set())
users[target_id][-1].add(logged_in_id)
save_users()
slow_print(f"你已成功关注用户 {users[target_id][0]}。")
def unfollow_user(logged_in_id, target_id):
"""取消关注用户"""
if target_id not in users:
slow_print("该用户ID不存在,请检查后重新输入。")
return
if target_id not in users[logged_in_id][3]:
slow_print("你没有关注该用户。")
return
users[logged_in_id][3].remove(target_id)
users[target_id][4].remove(logged_in_id)
# 移除目标用户新关注者标记
if hasattr(users[target_id], 'new_followers') and logged_in_id in users[target_id][-1]:
users[target_id][-1].remove(logged_in_id)
save_users()
slow_print(f"你已成功取消关注用户 {users[target_id][0]}。")
def accept_follow(logged_in_id, follower_id):
"""回关用户"""
if follower_id not in users:
slow_print("该用户ID不存在,请检查后重新输入。")
return
if follower_id not in users[logged_in_id][4]:
slow_print("该用户没有关注你,无法回关。")
return
if logged_in_id in users[follower_id][4]:
slow_print("你已经回关了该用户。")
return
users[logged_in_id][3].append(follower_id)
users[follower_id][4].append(logged_in_id)
# 移除新关注者标记
if hasattr(users[logged_in_id], 'new_followers') and follower_id in users[logged_in_id][-1]:
users[logged_in_id][-1].remove(follower_id)
save_users()
slow_print(f"你已成功回关用户 {users[follower_id][0]}。")
def view_user_profile(logged_in_id, target_id):
"""查看玩家主页"""
if target_id not in users:
slow_print("该用户ID不存在,请检查后重新输入。")
return
user_info = users[target_id]
username = user_info[0]
score = user_info[2]
follower_count = len(user_info[4])
following_count = len(user_info[3])
slow_print(f"用户主页 - {username}")
slow_print(f"用户ID: {target_id}")
slow_print(f"分数: {score}")
slow_print(f"粉丝数: {follower_count}")
slow_print(f"关注数: {following_count}")
if target_id in users[logged_in_id][3]:
slow_print("你已经关注了该用户。")
else:
follow_choice = input("是否关注该用户?(y/n): ").strip().lower()
if follow_choice == 'y':
follow_user(logged_in_id, target_id)
chat_choice = input("是否与该用户私聊?(y/n): ").strip().lower()
if chat_choice == 'y':
message = input("请输入要发送的消息:")
send_message(logged_in_id, target_id, message)
def my_info_menu(logged_in_id):
"""我的信息菜单"""
password = input("请输入密码以进入:")
if password != users[logged_in_id][1]:
slow_print("密码错误,返回主菜单。")
return
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. 查看新消息和新关注")
slow_print("8. 返回主菜单")
try:
choice = int(input("请选择操作(输入数字):"))
if choice == 1:
slow_print(f"用户名: {users[logged_in_id][0]}")
slow_print(f"用户ID: {logged_in_id}")
slow_print(f"分数: {users[logged_in_id][2]}")
slow_print(f"粉丝数: {len(users[logged_in_id][4])}")
slow_print(f"关注数: {len(users[logged_in_id][3])}")
elif choice == 2:
slow_print(f"密码: {users[logged_in_id][1]}")
elif choice == 3:
new_username = input("请输入新的用户名:")
users[logged_in_id][0] = new_username
save_users()
slow_print("用户名修改成功!")
elif choice == 4:
old_password = input("请输入原密码:")
if old_password != users[logged_in_id][1]:
slow_print("原密码错误,请重新输入。")
else:
new_password = input("请输入新密码:")
users[logged_in_id][1] = new_password
save_users()
slow_print("密码修改成功!")
elif choice == 5:
follow_list = users[logged_in_id][3]
if not follow_list:
slow_print("你还没有关注任何用户。")
else:
slow_print("我的关注:")
for idx, follow_id in enumerate(follow_list, start=1):
slow_print(f"{idx}. 用户名: {users[follow_id][0]}, 用户ID: {follow_id}")
elif choice == 6:
follower_list = users[logged_in_id][4]
if not follower_list:
slow_print("你还没有粉丝。")
else:
slow_print("我的粉丝:")
for idx, follower_id in enumerate(follower_list, start=1):
slow_print(f"{idx}. 用户名: {users[follower_id][0]}, 用户ID: {follower_id}")
elif choice == 7:
if hasattr(users[logged_in_id], 'new_messages'):
new_msg_count = len(users[logged_in_id][-1])
if new_msg_count > 0:
slow_print(f"你有 {new_msg_count} 条新私聊消息,发件人ID如下:")
for sender_id in users[logged_in_id][-1]:
slow_print(f" - {sender_id}({users[sender_id][0]})")
else:
slow_print("你没有新的私聊消息。")
if hasattr(users[logged_in_id], 'new_followers'):
new_follow_count = len(users[logged_in_id][-2])
if new_follow_count > 0:
slow_print(f"你有 {new_follow_count} 个新的粉丝,粉丝ID如下:")
for follower_id in users[logged_in_id][-2]:
slow_print(f" - {follower_id}({users[follower_id][0]})")
else:
slow_print("你没有新的粉丝。")
elif choice == 8:
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
def main_menu(logged_in_id):
"""游戏主页菜单"""
while True:
if hasattr(users[logged_in_id], 'new_messages') and len(users[logged_in_id][-1]) > 0:
new_msg_count = len(users[logged_in_id][-1])
slow_print(f"你有 {new_msg_count} 条新私聊消息,可在“我的”中查看。")
if hasattr(users[logged_in_id], 'new_followers') and len(users[logged_in_id][-2]) > 0:
new_follow_count = len(users[logged_in_id][-2])
slow_print(f"你有 {new_follow_count} 个新的粉丝,可在“我的”中查看。")
slow_print("欢迎来到恶魔之轮游戏!")
slow_print("1. 查看游戏规则")
slow_print("2. 玩家对战")
slow_print("3. 人机对战")
slow_print("4. 查看排行榜")
slow_print("5. 云聊天(私聊)")
slow_print("6. 社交功能")
slow_print("7. 我的")
slow_print("8. 退出游戏")
try:
choice = int(input("请选择操作(输入数字):"))
if choice == 1:
introduce_rules()
elif choice == 2:
player1_name = users[logged_in_id][0]
player2_id = input("请第二位玩家输入ID: ")
if player2_id not in users:
print("该ID不存在,请先注册。")
continue
player1 = {"name": player1_name, "health": 5, "items": get_random_items(), "coins": 0, "buffed": False, "handcuffed": False, "robot_active": False}
player2 = {"name": users[player2_id][0], "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 isinstance(player, dict) and player.get("handcuffed", False):
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("请输入操作编号:"))
opponent = player2 if player is player1 else player1
if action_choice == 1:
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_id][2] += 1
save_users()
elif player2["health"] <= 0:
slow_print(f"{player1['name']} 获胜!")
users[logged_in_id][2] += 1
save_users()
elif choice == 3:
player1_name = users[logged_in_id][0]
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.get("handcuffed", False):
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("请输入操作编号:"))
opponent = computer if player is player1 else player1
if action_choice == 1:
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[logged_in_id][2] += 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:
receiver_id = input("请输入接收方的ID: ")
message = input("请输入要发送的消息:")
send_message(logged_in_id, receiver_id, message)
elif chat_choice == 2:
receiver_id = input("请输入聊天对象的ID: ")
view_private_chat_history(logged_in_id, receiver_id)
elif chat_choice == 3:
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
elif choice == 6:
while True:
slow_print("社交功能菜单:")
slow_print("1. 关注用户")
slow_print("2. 取消关注用户")
slow_print("3. 回关用户")
slow_print("4. 查看用户主页")
slow_print("5. 返回主菜单")
try:
social_choice = int(input("请选择操作(输入数字):"))
if social_choice == 1:
target_id = input("请输入要关注的用户ID:")
follow_user(logged_in_id, target_id)
elif social_choice == 2:
target_id = input("请输入要取消关注的用户ID:")
unfollow_user(logged_in_id, target_id)
elif social_choice == 3:
follower_id = input("请输入要回关的粉丝ID:")
accept_follow(logged_in_id, follower_id)
elif social_choice == 4:
target_id = input("请输入要查看主页的用户ID:")
view_user_profile(logged_in_id, target_id)
elif social_choice == 5:
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
elif choice == 7:
my_info_menu(logged_in_id)
elif choice == 8:
slow_print("感谢游玩,再见!")
break
else:
slow_print("输入无效,请重新输入!")
except ValueError:
slow_print("输入无效,请输入数字!")
if __name__ == "__main__":
load_users()
while True:
print("1. 注册")
print("2. 登录")
print("3. 退出")
try:
main_choice = int(input("请选择操作(输入数字):"))
if main_choice == 1:
user_id = register()
if user_id:
main_menu(user_id)
elif main_choice == 2:
user_id = login()
if user_id:
main_menu(user_id)
elif main_choice == 3:
slow_print("感谢使用,再见!")
break
else:
print("输入无效,请输入数字!")
except ValueError:
print("输入无效,请输入数字!")
全部评论 3
报错了
2025-03-10 来自 浙江
0这个代码能放到acgo在线IDE里面吗
2025-02-18 来自 浙江
0应该不能,因为ACGO的IDE应该不支持我的代码
2025-02-19 来自 浙江
0我也不确定
2025-02-19 来自 浙江
0好像是不行
2025-02-19 来自 浙江
0
@𝒹𝓇ℯ𝒶𝓂
报错了
Traceback (most recent call last):
File "C:\Users\fu'hong'yun\Desktop\11.py", line 1010, in <module>
load_users()
File "C:\Users\fu'hong'yun\Desktop\11.py", line 33, in load_users
score = int(parts[3])
IndexError: list index out of range2025-02-12 来自 浙江
0全文总结
这段内容是一个错误回溯信息,显示在运行 “C:\Users\fu'hong'yun\Desktop\11.py” 文件中的模块时出现问题。具体是在调用load_users()函数时发生了错误。错误类型为IndexError,即列表索引超出范围。错误发生在尝试将列表中的元素转换为整数时,表明列表中可能没有足够的元素供索引为 3 的位置使用。
重要亮点
错误发生位置:在 “C:\Users\fu'hong'yun\Desktop\11.py” 文件中,当运行到第 1010 行的<module>模块中调用load_users()函数时出现错误。
错误类型:错误为IndexError,表明列表索引超出范围。
具体错误情况:在load_users()函数中,尝试使用parts[3]索引列表中的元素并将其转换为整数时出现问题,说明列表长度不足,没有索引为 3 的元素。2025-02-13 来自 浙江
0所以咋改?不会python
2025-02-13 来自 浙江
0
有帮助,赞一个