python文本冒险验证用户输入

时间:2015-03-08 14:54:12

标签: python python-3.x text adventure

一个简单的问题我真的陷入了我的文本冒险游戏如何在输入多个单词时验证用户输入。我希望他们能够在枝形吊灯或类似的东西上写火,但我只能让它一次验证一个单词。

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

1 个答案:

答案 0 :(得分:0)

试试这个:

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

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