Jul-24-2018, 11:16 AM
Hi,
So I am writing a very basic text based game, and have put a loop withing a loop for depending upon which game branch I go down. I was wondering how I can break out of both loops, or perhaps the code I have written is a bad way to do this. (I have simplified my code to give you up to where I want to break.
Many thanks!!
So I am writing a very basic text based game, and have put a loop withing a loop for depending upon which game branch I go down. I was wondering how I can break out of both loops, or perhaps the code I have written is a bad way to do this. (I have simplified my code to give you up to where I want to break.
Many thanks!!
def game():
print("Welcome to the game.")
print("You see a robber in the courtyard. What do you want to do?\n")
attack = ["scream","shout","attack","hit","punch","kick"]
while True:
game()
courtyard_decision = input(">>").lower().split()
if set(courtyard_decision) & set(attack):
print("You have decided to get into a fight with the Robber")
while True:
print("""The robber dodges your first attack.
He then throws a punch and you slip to the left.
Would you like to throw a left or right hook?""")
fight = input(">>>").lower().split()
if "left" in fight or "right" in fight:
print("Your hook hits the robber and you have completed the game!")
break
