mercredi 12 décembre 2018

I have an if function in a while loop, but it either ignores it or doesn't break

while True:
    print("We have entered in the open sea, but the current is pushing us. We 
                can veer left and"
          +"\nmiss the storm, or go straight through it. Type [left] or 
            [straight] exactly as it is in the box.")
    turnChoice = input()

    if turnChoice == "left":
        food = food - 2
        time.sleep(2)
        print("You missed the storm, but you lost a little food. Your current 
              food level is 5. If you let it go to zero, "
              +"\nyour health will decrease.")
        break
    if turnChoice == "straight":
        time.sleep(2)
        random.randint(1,5)
        break
    if random == 1:
        food = food - 2
        print("You tried to go through the storm, but the ship was damaged. You 
                lost some food.")
        break
    if random == 2:
        print("The ship made it through the storm without taking damage somehow. 
                You did not loose any supplies or health.")
        break
    if random == 3:
        print("The ship made it through. It made a lot of noise, but no supplies 
                were lost.")
        break
    if random == 4:
        health = health - 20
        print("The ship made it through, but there was damage. While you were 
                inside the ship, a stack of barrels fell on you."
                +"\n You took some damage, receiving a concussion and fracturing 
                your arm. But you will live.")
        break
    if random == 5:
        water = water - 2
        print("You made it through the storm, but some water barrels were lost 
                to the storm. ")
        time.sleep(2)
        print("Here is your water status, don't let it get to zero: ")
        print(water)
        break

    if turnChoice not in("left", "straight"):
        print("Invalid input, please try again.")

Sorry if it is formatted bad, I'm new to stackoverflow. I'm programming a word game for my English project. I'm trying to run these different 'if' functions inside the 'while' loop, but it either ignores them, or just loops the whole function. If you choose "straight", then it should pull a random number generator and choose a random scenario. If you choose "left", it just decreases your food. The "left" function works, but the "straight" does not. Also, I am trying to get it to break after it runs through either the 'left' function or 'straight' function, but I am not sure how to because of the 'if' functions. This is programmed on Pycharm, and I believe it is python 3.7.0.

Aucun commentaire:

Enregistrer un commentaire