创建一个RPG游戏箱

时间:2019-05-14 00:47:37

标签: python

因此,我正在尝试为我正在从事的rpg游戏创建箱子,并且在实现概率以及确保一件物品始终掉落时,我遇到了非常困难的时间。我能够降低概率,但是每当它起作用时,我都无法与武器一起使药水掉落。任何帮助将不胜感激!是的,我的物品是从妖精的尾巴上命名的。

我已经尝试过给物品增重,但是即使如此,我也无法确保药水掉落



我上面的代码就是我正在工作的代码。考虑到我是自学成才,没有上学,很难找到能完全帮助我的东西。

1 个答案:

答案 0 :(得分:4)

如果您始终想要药水和其他物品,则可以执行以下操作:

print("You found a potion plus a " + random.choice(Chestitems))

另外,安排您的common / rare / etc可能更好。项目放在单独的列表中:

common_items = ["Bow", "Sword", "Spear"]
uncommon_items = ["Irondragon Bow", "Irondragon Sword", "Irondragon Spear"]
# etc. for rare_items and legendary_items

然后,您可以将随机数从1滚动到100,以选择要选择的列表:

die_roll = random.randint(1, 100)
if die_roll < 75:
    items = common_items
elif die_roll < 90:
    items = uncommon_items
elif die_roll < 98:
    items = rare_items
else:
    items = legendary_items

print("You found a potion plus a " + random.choice(items))