我正在制作一个 python 程序,它是一个通过鬼屋的冒险游戏。其中最重要的内容之一是一个名为 的列表owned_items
。这会获取由字符串表示的项目,例如“火柴盒”或“火炬”,当他们在房子里找到它们时,或者在开始时给它们random.choice
。有时,当他们遇到某种情况时,他们得到什么选择取决于他们是否有特定的项目。
我的代码:
#bullets is the variable for pistol ammo. During my testing of this function, it is at 5 when it should start
bullets=5
owned_items=[]
ronald_items=["a glass bottle", "a pistol", "a torch", "a small glass of oil", "a box of matches", "a can of spray paint", "a small knife", "a pair of surgical gloves", "a blessed amulet"]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[0]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[1])
#This part is in the actual definition where the problem appears when it should run
def skeleton_choice():
if "a glass bottle" in owned_items:
print('type "glass bottle" to attack the skeletons with that bottle')
if "a pistol" in owned_items and bullets>1:
print('type "shoot" to try firing your pistol at the skeletons')
if "a small knife" in owned_items:
print('type "small knife" to use your small knife against the skeletons')
if "a kitchen knife" in owned_items:
print('Type "kitchen knife" to use your kitchen knife against the skeletons')
if "a blessed amulet" in owned_items:
print('Type "amulet" to use the blessed amulet to make this a fairer fight')
print('Type "hands" to just fight the skeletons with your body')
print('Type "run" to try and get away from the skeletons')
即使我知道我在这些 if 语句中有 3 个项目,也没有任何打印出现。我使用的是 ifs 而不是 elifs 和一个 else,因为我希望它显示他们拥有的所有东西的打印,而不仅仅是一个。例如,如果他们有一个玻璃瓶和一把菜刀,我希望它给他们瓶子和刀的印刷说明。