Just a quick question. I'm really stuck with my text adventure game. How do I validate user input when they are entering more than one word? I want them to be able to write fire at chandelier
or something similar, but I can only get it to validate one word at a time.
print("input fire chandelier")
user = input()
if user in ("fire", "chandelier"):
print("works")
else:
print("fails")
Right now my shooting code looks like this. It only validates one word.
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