地牢爬虫功能无法正常工作

时间:2017-04-29 02:24:57

标签: python

我正在构建一个基本的地牢爬虫游戏,我似乎无法让我的一个功能正常工作。我已经尝试过使用缩进来查看它是否是由此引起的,但到目前为止还没有运气,这是它当前状态下的功能:

def prisoner_encounter():
    global player_health
    global room_count
    scroll_text("\nYou kick open a rusted metal door and a faint raspy voice calls out to you from inside the darkness.")
    time.sleep(1)
    print("\n ")
    scroll_text("\nHey...")
    time.sleep(2)
    print("\n ")
    scroll_text("\nHey you...")
    time.sleep(2)
    print("\n ")
    scroll_text("\nPlease help me...")
    time.sleep(1)
    print("\n ")
    scroll_text("\nYou look at the rotting old man, he's chained to wall by all four limbs.")
    time.sleep(1)
    print("\n ")

    security = True
    while security == True:

        choice = input("\nDo you try to help him? [ y | n ] ")
        print("\n ")
        if choice == "y" or choice == "n":
             security = False

        if choice == "y":
            yes_choice = random.randint(1,2)

        if yes_choice == "1":
            scroll_text("\nYou spend what seems like an eternity fiddling with the lock. Finally you hear a click and the chains fall to the ground.")
            time.sleep(1)
            print("\n ")
            scroll_text("\nThe old man thanks you for your help and tends to some of your wounds, +2 health.")
            player_health = player_health + 2
            time.sleep(1)

        if yes_choice == "2":
            scroll_text("\nYou spot a rock in the corner of the cell and use it to smash the lock off the man's chains.")
            time.sleep(1)
            print("\n ")
            scroll_text("\nUnexpectedly the man sucker punches you in the side of the head and disappears down the corridor, -2 health.")
            player_health = player_health - 2
            time.sleep(1)

        if choice == "n":
            scroll_text("\nYou apologise to the man and explain that must keep moving in order to escape. You try not to think about him.")
            time.sleep(1)

它应该做的是给你一个是或否的选择来帮助一个男人,如果你选择是的,有一个好的结果和一个糟糕的结果,每个50/50的机会,如果你选择不,你只是继续

1 个答案:

答案 0 :(得分:1)

我看到了几个问题。首先,choice == "y"条件的分支逻辑应缩进一级。其次,randint将返回一个整数,因此您的比较应删除整数12周围的引号:

def prisoner_encounter():
    global player_health
    global room_count
    scroll_text("\nYou kick open a rusted metal door and a faint raspy voice calls out to you from inside the darkness.")
    time.sleep(1)
    print("\n ")
    scroll_text("\nHey...")
    time.sleep(2)
    print("\n ")
    scroll_text("\nHey you...")
    time.sleep(2)
    print("\n ")
    scroll_text("\nPlease help me...")
    time.sleep(1)
    print("\n ")
    scroll_text("\nYou look at the rotting old man, he's chained to wall by all four limbs.")
    time.sleep(1)
    print("\n ")

    security = True
    while security == True:

        choice = input("\nDo you try to help him? [ y | n ] ")
        print("\n ")
        if choice == "y" or choice == "n":
             security = False

        if choice == "y":
            yes_choice = random.randint(1,2)

            if yes_choice == 1:
                scroll_text("\nYou spend what seems like an eternity fiddling with the lock. Finally you hear a click and the chains fall to the ground.")
                time.sleep(1)
                print("\n ")
                scroll_text("\nThe old man thanks you for your help and tends to some of your wounds, +2 health.")
                player_health = player_health + 2
                time.sleep(1)

            elif yes_choice == 2:
                scroll_text("\nYou spot a rock in the corner of the cell and use it to smash the lock off the man's chains.")
                time.sleep(1)
                print("\n ")
                scroll_text("\nUnexpectedly the man sucker punches you in the side of the head and disappears down the corridor, -2 health.")
                player_health = player_health - 2
                time.sleep(1)

        elif if choice == "n":
            scroll_text("\nYou apologise to the man and explain that must keep moving in order to escape. You try not to think about him.")
            time.sleep(1)