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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
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() |