So, I am trying to code a text-based adventure game here. I am doing this in order to master branches, functions, and, importantly, loops (while and for). My game is pretty big, so here is the exact section of the code I am stuck with:
def grand_battle():
print("You head up north.")
print("Suddenly, 4 spaceships emerge. They all emerged from behind astroids in the area. The area is filled with astroids and is tough to navigate.")
print("You must activate your defense systems, but your ships hits an astroid.")
print("You have a couple of options here.")
print("First, you can focus firepower on the 4 unidentified ships.")
print("Second, you can try to escape by firing suppressing fire at the other 4 ships. This ensures they keep a distance while your crew repair the ship.")
print("Third, you can chase the cargo ship. You and your crew can embark it, kill or capture all crew memebers inside, and use this new ship to escape.")
print("Fourth, you tell the spaceships you are freindly. You inform them that all you need is passage through this area, to arrive to your intended destination (this is a lie, as you know).")
print("Which option do you pick")
option = input("> ")
if "First" in option:
print("Your automatic turrets pierce through 2 adjacent ships. The main dock is broken and their crews are in distress. The ships loose balance, fire begins to engulf them, and a huge amount of metal scrap starts to float around.")
print("You have destroyed the first two ships.")
print("Meanwhile, the two other ships decide to surround you.")
print("One heads directly towards you. It fires two missiles at your ship.")
print("Your turrets hit the ship, but your ship is also hit by 1 of the missiles; the other hit an astroid.")
print("Your ship is now in distress and emergency sounds are triggered inside the cabin.")
print("The other ship behind you crashes on an astroid. Lucky.")
print("The cargo ship escapes.")
print("You and your crew mates take the escape pods and you all land in some rimworld.")
print("What happens there is a story for another time.")
print("Game over.")
if "Second" in option:
print("The ships keep a distance and try to blast you from a distance.")
print("You are overwhelmed by the hostile firepower.")
print("You have two options: ")
print("One, you take the escape pods and hope you land somewhere safe.")
print("Two, you keep firing. If you are lucky, the ship is repaired and you can escape the place.")
print("Which option do you choose")
option1 = input("> ")
if "One" in option1:
print("Your crew escapes. So do you.")
print("You land in a rimworld far far away. What happens there is a story for another time.")
print("Game over.")
elif "two" in option1:
print("The crew repairs the ship. Your trust and patience have been rewarded.")
print("Congratulation, the ship works better than ever.")
print("You turn back and launch hyperdrive.")
print("You survived.")
print("Good job!")
print("Game over.")
else:
dead()
if "Third" in option:
print("You enter the ship. It is dark. There are two doors. One to your left and another to your right.")
print("Which door do you choose?")
door = input("> ")
if door == "left":
print("You find a snake inside.")
dead()
elif door == "right":
gold_room()
else:
print("You did not react.")
print("You ran out of time and the ship has been boarded by ennemy forces.")
dead()
if "Fourth" in option:
print("The spaceships escort you away from the cargo ship.")
print("Game over")
else:
print("Learn to type!")
dead()
So, this is a function that is triggered by another choice the user makes earlier in the game. In this function, I ask the user to choose from First to Fourth. How can I write a condition where if the user types anything other than "First" "Second" "Third" "Fourth", the program replies back to the user saying "Oops! I did not understand that" "Try again". After the try again, the user will be given the option prompt once more. If he puts the wrong answer, he will receive the same message. If he puts the right answer, the program continues.