只是一个快速的问题。我真的被我的文字冒险游戏困住了。当用户输入多个单词时,如何验证用户输入?我希望他们能够写作fire at chandelier
或类似的东西,但我一次只能验证一个词。
print("input fire chandelier")
user = input()
if user in ("fire", "chandelier"):
print("works")
else:
print("fails")
现在我的射击代码看起来像这样。它只验证一个词。
user = input()
if user == "cover" or user == "stand" or user == "reload" or user == "fire"
or user == "wait" or user == "chandelier":
while turn >= 1:
#player shoots if fire entered shoot is greater than 1
#and player is standing
elif user == "fire" and shoot >= 1 and standing == True and chandelier < 2:
#does hit random number between 1 and 2 1 hits 2 misses
doesHit = random.randint(1, 2)
if doesHit == 1:
print("you shoot one round hitting Martin but his skin is made of metal the bullet bounces off")
#-1 ammo
shoot = shoot - 1
#check if in cover
cover = False
#counts down turn
turn = turn - 1
break
elif doesHit > 1:
print("you shoot but it misses")
turn = turn - 1
shoot = shoot - 1
break
#shoot the chandelier to damage martin
elif user in ["fire", "chandelier"] and shoot >= 1 and standing == True:
doesHit = random.randint(1, 2)
if doesHit == 1:
print("You shoot one round hitting the chandelier it hangs by one chain")
#-1 ammo
shoot = shoot - 1
#check if in cover
cover = False
#counts down turn
turn = turn - 1
chandelier = chandelier + 1
break
elif doesHit > 1:
print("you shoot but it misses")
turn = turn - 1
shoot = shoot - 1
break
#can shoot martin now chandelier has fallen
elif user == "fire" and shoot >= 1 and standing == True and chandelier >= 2:
#does hit random number between 1 and 2 1 hits 2 misses
doesHit = random.randint(1, 2)
if doesHit == 1:
print("you shoot one round hitting Martin")
#-1 ammo
shoot = shoot - 1
#check if in cover
cover = False
#counts down turn
turn = turn - 1
break
elif doesHit > 1:
print("you shoot but it misses")
turn = turn - 1
shoot = shoot - 1
break