0

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
aschultz
  • 1,658
  • 3
  • 20
  • 30
  • Can you explain better what you are trying to do? Right now you are taking user input, which you are confusingly calling `user`, then testing if it is either the word `'fire'` or the word `'chandelier'`. You could get what you're actually asking about working by adding `'fire chandelier'` or `'fire at chandelier'` to the tuple, but that doesn't look like what you want to do either. – Two-Bit Alchemist Mar 08 '15 at 14:58
  • Always use `raw_input()` instead of `input()` (if using Python 2.x). See this: http://stackoverflow.com/a/7710959/1268926 – Kedar Mar 08 '15 at 15:01
  • @kedar Not in Python 3. – cdonts Mar 08 '15 at 15:02
  • I want it to validate for two different cases the player can shoot taking one turn however they can also shoot the chandelier. I want to validate if they chose to shoot the chandelier or just normally shoot – Zac Connolly Mar 08 '15 at 15:02

1 Answers1

0

Try this :

print("input fire chandelier")
user = input()

if "fire" in user or "chandelier" in user:
     print ("works")
else:
     print("fails")