Apr-06-2018, 05:12 PM
Hello,
I am doing a simple text adventure game for school and so far I have the following.
On line 61 (elif choice == 2:) which in the function prompt 3, I am getting an unexpected
unindent error. I assume it has something to do with the indentation but I can't figure it out.
Can anyone plug this into IDLE and debug it?
Please keep in mind I am new to the language and I'm completely aware that this code may be unprofessional or over complicated.
Thanks!
I am doing a simple text adventure game for school and so far I have the following.
On line 61 (elif choice == 2:) which in the function prompt 3, I am getting an unexpected
unindent error. I assume it has something to do with the indentation but I can't figure it out.
Can anyone plug this into IDLE and debug it?
Please keep in mind I am new to the language and I'm completely aware that this code may be unprofessional or over complicated.
Thanks!
import time global playerhealth global enemyhealth enemyhealth = 25.0 playerhealth = 50.0 bosshealth = 100.0 global guessed def prompt2(): print(""" You walk into a cave. You are scared. Do you chose to continue or turn around? Type '1' or '2'. 1: Turn around 2: Continue """) choice = int(input("What will you do?: ")) try: if choice == 1: youLose() elif choice == 2: print("Good choice, " + name + ", let's continue!" ) prompt3() else: print("Not valid!") prompt2() except NameError: print("You need to type a single number to reflect your choice!") prompt2() def prompt3(): print(""" You run into a skeleton ghoul. You also hear the mysterious ghost's laugh echo through the cave. What is your weapon of choice? 1: Sword 2: Bow 3: Staff """) choice = int(input("How will you fight?: ")) try: if choice == 1: print(""" Great! Will you attack fast or slow? 1: Fast 2: Slow """) choiceSword = int(input("Fast or slow?: ")) try: if choiceSword == 1: prompt4() if choiceSword == 2: print("You attacked too slow and he stabbed you!") youLose() elif choice == 2: print("Good choice, " + name + ", let's continue!" ) prompt4() elif choice == 3: print(""" You chose a staff, a versatile weapon. Will you choose to attack first? Or defend? Or fight by hand? 1: Attack 2: Defend 3: Fight By Hand """) choiceStaff = int(input("How will you use the staff?: ")) try: if choiceStaff == 1: prompt4() elif choiceStaff == 3: youLose() elif choiceStaff == 2: while enemyhealth >= 0: print(""" The skeleton breaks your shield and damages you 4.6 health! """) playerhealth -= 4.6 print("You have " + str(playerhealth) + " health remaining!") attackStaff = raw_input("Do you wish to attack? ('yes' or 'no'): ") if attackStaff == yes: enemyhealth -= 26 print(""" You attacked the enemy with a critical hit. You killed him. """) prompt4() elif attackStaff == no: print("Your being too timid!") youLose() else: print(""" You need to type either 'yes' or 'no'! Rolling back to start of phase! """) prompt3() except NameError: print("You need to type a single number to reflect your choice!") prompt3() else: print("Not valid!") prompt2() except NameError: print("You need to type a single number to reflect your choice!") prompt2() def prompt4(): print(""" The ghost can only be stopped by his defeat or a guess. Guess the ghost! 1: Arnold 2: Sam 3: Pluto """) guess = int(input("Who is the ghost(1, 2, or 3)?: ")) try: if guess == 1: youWin() if guess == 2: guessed = 2 print("Wrong! Moving on!") prompt5() if guess == 3: guessed = 3 print("Wrong! Moving on!") prompt5() except NameError: print("Type an integer to reflect your answer!") prompt4() def prompt5(): print(""" You come to a lake. Do you jump in or turn to your left? 1: Jump In 2: Turn Left """) prompt5answer = int(input("Do you jump or turn?: ")) try: if(prompt5answer == 1): print("You drowned!") youLose() elif(prompt5answer == 2): print("Good choice! Moving along....") prompt6() except NameError: print("Type an integer to reflect your answer!") prompt5() def prompt6(): print(""" The ghost can only be stopped by his defeat or a guess. Guess the ghost! """) if guessed == 2: print(""" 1: Arnold 2: Pluto """) if guessed == 3: print(""" 1: Arnold 2: Sam """) guess2 = int(input("Guess the ghost: ")) try: if guess2 == 1: youWin() elif guess2 == 2: print("Wrong! You notice the rocks on the walls start to rumble.") print("You see a white light slowly form into a figure. Could it be?") time.sleep(2) bossFight() except NameError: print("Type an integer to reflect your answer!") prompt6() def bossFight(): print(""" The ghost is revealeed to you as Arnold! """) print("The boss still has " + str(bosshealth) + " remaining!") print("You still have " + str(playerhealth) + " remaining! Good luck!") while playerhealth > 0 and bosshealth > 0: print(""" Arnold glares at you. Do you choose to attack or defend? 1: Attack 2: Defend """) choiceBoss = int(input("Do you attack or defend?") try: if choiceBoss == 1: print("You attack the boss for 23.6 health!") bosshealth -= 23.6 print("The boss has " + str(bosshealth) + " remaining!") print() elif choiceBoss == 2: print("The boss attacks you for 10.0 health!") playerhealth -= 10.0 print("You have " + str(player) + " remaining!") print() if playerhealth < 0: print("You have been defeated.") youLose() if bosshealth < 0: youWin() else: continue except NameError: print("Type an integer to reflect your answer!") prompt4() def hitBoss(): print("You damage the boss!") bosshealth -= 10 if bosshealth > 0: print("The boss still has " + str(bosshealth) + " remaining!") def youLose(): print("Nice try, " + name + ", try again next time!") def youWin(): print("Congratulations!") print("You either killed or guessed the ghost, Arnold!") print("Good job, " + name + "! Come back to the castle soon!") def start(): print("Welcome to the Castle! The castle is haunted by a ghost!") time.sleep(1) print("For centuries, many have tried to figure out who it was.") time.sleep(1) print("No one has. Until now...") time.sleep(2) print() global name name = raw_input("Enter your name: ") startPrompt() def startPrompt(): global prompt1 prompt1 = raw_input("Type 'start' to start the game: ") if prompt1 == "start": print("Starting game.....") print() time.sleep(2) prompt2() else: print() print("You're dumb! Type 'start' stupid!") startPrompt() start()