Хотя цикл и операторы if в функции. Останавливается перед переходом к оператору if - PullRequest
0 голосов
/ 14 октября 2019

'Текстовая история / приключение'

Мне просто нужно, чтобы бой закончился и выполнял другие функции в зависимости от игрока или бандитов, имеющих уровень hp == 0. У меня есть класс Player ()и p1 и бандиты - это два отдельных экземпляра класса с начальным значением hp, равным 2. "self.hp = 2"

Я хотел бы отметить, что бандиты - это "два" человека в истории, ноони составляют «один» экземпляр в классе «Player». Это специально. Эта история не должна бросать вам вызов слишком много. Я мог бы использовать некоторую помощь, чтобы выйти из боя.

Я получаю это в консоли:

Early in the morning, you are startled so bad you shoot up out of your blanket!
You hear a ruckus in the wagon next to you and find a couple of bandits
sneaking off with the food the whole wagon train eats from.

You've got to do something fast. There are only two of em, and they look pretty scrawny.

[A] Fight like a man. Save the food supply.
[B] Holler for help from the nice lady in the wagon over yonder... then run away.
[M] View Map
[I] View Bag
*************************
What are you gonna do?
 >a
 --- FIGHT THE BANDITS! --- 
1) Left hook
2) Right hook
3) Spur em with your boots!


Pick a move
> 3
You got em good. Both bandits are lookin' skeerd now!
 --- FIGHT THE BANDITS! --- 
1) Left hook
2) Right hook
3) Spur em with your boots!


Pick a move
> 2
You got em good. Both bandits are lookin' skeerd now!

Process finished with exit code 0

Вот код: Как я могу перейти к следующей сцене.

### FIGHT FUNCTION ### (TRIGGER UNLOCK) ###
def fight():
    if p1.hp == 0:
        bandits_won
    elif bandits.hp == 0:
        p1_won
    else:
        pass
    while p1.hp > 0 and bandits.hp > 0:
        print(" --- FIGHT THE BANDITS! --- ")
        print("1) Left hook\n2) Right hook\n3) Spur em with your boots!\n\n")
        act = int(input("Pick a move\n> "))
        if act in range(1,4):
            bandits.hp -= 1
            print("You got em good. Both bandits are lookin' skeerd now!")
            continue
        else:
            print("That wasn't an option bozo! You got a knuckle sandwich and lost [1] HP!")
            p1.hp -= 1
            print("You have ", p1.hp, " HP left! Don't miss again!!!")
            continue
    p1_won = False
    bandits_won = False
    if p1_won == True:
        print("You got them suckers. The wagon train is grateful. You grab a bite for your trouble.")
        p1.hp = 2
        scene3()
    elif bandits_won == True:
        delay_print("They knocked you out cold, took the food, and the whole wagon train suffered. Croup took the "
                    "child...\n")
        delay_print("You failed your mission. No sense in going on now!")
        main_menu()

1 Ответ

0 голосов
/ 14 октября 2019

Мне кажется, что вы никогда не присваиваете значение True переменным p1_won или bandits_won. Переместите этот код так, чтобы он был ниже цикла while.

if p1.hp == 0:
        bandits_won = True
    elif bandits.hp == 0:
        p1_won = True
    else:
        pass

Вы также можете упростить if p1_won == True: до if p1_won: и то же самое для оператора elif

...