944,110 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1133
  • Python RSS
Oct 29th, 2006
0

tribute project for daniweb

Expand Post »
Hey, I am trying to create my text adventure geared towards all of the frequent posters on daniweb's python forum, just alittle something to have fun with. But, it isn't going as planned. I used vegaseat's suggestion for combat, shuffling lists randomly to randomize hit/miss results. I think I did it wrong. I got many errors, I think I fixed most of them, except for the "expected an indent block" message I got (I noted the line with a comment in the source). So, if any of you would like to help me with this project I would appreciate it. I will give full credit to ALL who contribute to this project in the source as well as in the credits of the program itself. Here is the code I am working with:
Python Syntax (Toggle Plain Text)
  1. # Decided to make a simpler Text based game
  2. # will try to use classes and functions primarily
  3. # I am going to try vegaseat's suggestion for combat
  4. # creating a hit list for player and monster
  5. # then using random.shuffle to mix it up
  6. # where list = [1, 0, 2, 0, 3, 0, 0, 1]
  7. # and where 0 = miss
  8. # 1 = minor boo-boo
  9. # 2 = black and blue
  10. # 3 = ER visit and possible stiches
  11. # (minor to major damage) lol
  12. # this is going to be a text based tournament simulator
  13. # "TEXT KWON DO" v1.0
  14. # by Franki
  15. # ten victories to win the competition!
  16. import random
  17. import math
  18.  
  19. myhitlist = [1, 0, 2, 0, 3, 0, 0, 1]
  20. enemyhit_list = [1, 0, 2, 0, 3, 0, 0, 1]
  21. myhp = 20
  22. enemyhp = 15
  23. myhit_list2 = [1, 0, 1, 2, 0]
  24. print ''' TEXT KWON DO
  25. The ultimate text based martial arts tournament!
  26. Created especially for the many fine folks at
  27. <a rel="nofollow" href="http://www.daniweb.com's" target="_blank">www.daniweb.com's</a> Python forum. '''
  28. print
  29. raw_input("Press Enter to continue: ")
  30. start()
  31. def start():
  32. print '''Are you ready fighter! Are you ready to pit your martial arts
  33. typing skills against the best of the Text Kwon Do Federation? You will
  34. need nerves of steel, and the muscle to match, to win this competition.
  35. If you can survive ten fights, each time beating your adversary, you win
  36. the title of 'Text Kwon Do World Champion!' Good luck, and have no mercy! '''
  37. print
  38. raw_input("Press enter to continue: ")
  39. game_controls()
  40. def game_controls():
  41. print ''' Gameplay is carried out in the following fashion. On your turn, you type in your
  42. command. The available commands are 'punch' 'kick' 'headbutt' 'super punch' super kick' and
  43. 'rage attack'. Each attack does different amounts of damage. During the game, you can type
  44. 'help' to come back to this screen at anytime during your turn. '''
  45. print
  46. raw_input("Press enter to continue: ")
  47. enter_ring()
  48. def enter_ring():
  49. print ''' You are about to enter the ring, soldier! Prepare yourself, do some push-ups,
  50. pull-ups, kick stuff, do some karate chops, throw a few fireballs (hint hint) and when
  51. you are ready, type 'start fight' to commence the beatings! '''
  52. print
  53. prompt_a()
  54. def prompt_a():
  55. prompt_this = raw_input("What do I do Sensai? ").lower()
  56. try:
  57. if prompt_this == "start fight":
  58. fight_one()
  59. elif prompt_this == "help":
  60. game_controls()
  61. else:
  62. print "You must say 'start fight', Daniel San!"
  63. except: # I believe Ene Uran from daniweb's python forum told me to do this with pass
  64. pass
  65. prompt_a()
  66. # taking first break.
  67. # when return, need to define fight_one()
  68. # need to create myhit_list and enemy.namehit_List where enemy.name = name of enemy; ex. forumlurkerhit_list
  69. # try to figure out a way for each attack to do higher damage
  70. # one idea is to make different hit lists for each attack
  71. # another idea is to figure out how to have each attack
  72. # filter out some integers and return only specific ones.
  73. # for fight_one() I need to make:
  74. # ring1_desc(), fighter1_desc(), the main battle script,
  75. # and then test.
  76. # try NOT TO USE PYTHON FORUM UNLESS I ABSOLUTELY CANNOT FIGURE IT OUT!!!!
  77. # first break taken at 10/27/06 1:28 pm
  78. # break ended 10/29/06 3:23 pm
  79. # now defining fight_one()
  80. # fight_one() includes ring1_desc(), fighter1_desc(), and main battle script (fight_one() )
  81. def fight_one():
  82. myhit_list[1, 0, 2, 0, 3, 0, 0, 1]
  83. c++punkhit_list[1, 0, 2, 3, 0, 0, 1]
  84. print '''You are in the ring. Your opponent, C++ Punk, is on the opposite end of the ring.
  85. The referee yells "Fight!", and the battle commences. Type 'help' for a list of commands. '''
  86. print
  87. prompt_fight1()
  88. def prompt_fight1():
  89. raw_input("What do you do, Daniel San?").lower()
  90. try:
  91. if prompt_fight1 == "help" or prompt_fight1 == "help commands":
  92. game_controls()
  93. elif prompt_fight1 == "punch" or prompt_fight1 == "kick":
  94. x = random.shuffle(myhitlist)
  95. if x == '0':
  96. print 'You missed!'
  97. enemy_turn()
  98. elif x == '1':
  99. print 'You hit C++ Punk!'
  100. enemyhp = enemyhp - 1
  101. enemy_turn()
  102. elif x == '2':
  103. print 'You hit C++ Punk hard!'
  104. enemyhp = enemyhp - 2
  105. enemy_turn()
  106. elif x == '3':
  107. print 'You hit C++ Punk really hard!'
  108. enemyhp = enemyhp - 3
  109. enemy_turn()
  110. elif prompt_fight1 == "headbutt" or prompt_fight1 == "super punch" or prompt_fight1 == "super kick" or prompt_fight1 == "rage attack":
  111. x = random.shuffle(myhitlist)
  112. if x == '0':
  113. print 'You missed!'
  114. enemy_turn()
  115. elif x == '1':
  116. print 'You hit C++ Punk!'
  117. enemyhp = enemyhp - 1
  118. enemy_turn()
  119. elif x == '2':
  120. print 'You hit C++ Punk hard!'
  121. enemyhp = enemyhp - 2
  122. enemy_turn()
  123. elif x == '3':
  124. print 'You hit C++ Punk really hard!'
  125. enemyhp = enemyhp - 3
  126. enemy_turn()
  127. elif prompt_fight1 == "fireball":
  128. n = random.shuffle(myhit_list2)
  129. if n == '0':
  130. print 'You missed'
  131. enemy_turn()
  132. elif n == '1':
  133. print 'You missed'
  134. enemy_turn()
  135. elif n == '2':
  136. print 'You hit C++ Punk very freakin hard!'
  137. enemyhp = enemyhp - 5
  138. enemy_turn()
  139. if enemyhp == 0:
  140. print 'You defeated C++ Punk! Prepare for the second fight!' #error: expected indented block
  141. fight_two()
  142. else:
  143. print 'That is not a Text Kwon Do technique, Daniel San!'
  144. except:
  145. pass
  146. # this is supposed to be the oppenents turn, [enemy_turn() ]
  147. # Still get many syntax errors but everything seems to line up fine
  148. # need to learn to read the error messages
  149. def enemy_turn():
  150. x = random.shuffle(enemyhit_list)
  151. if x == '0':
  152. print 'C++ Punk missed!'
  153. prompt_fight1()
  154. elif x == '1':
  155. print 'C++ Punk hit you!'
  156. myhp = myhp - 1
  157. prompt_fight1()
  158. elif x == '2':
  159. print 'C++ Punk hit you hard!'
  160. myhp = myhp - 2
  161. prompt_fight1()
  162. elif x == '3':
  163. print 'C++ Punk hit you really hard!'
  164. prompt_fight1()
  165. elif myhp == 0:
  166. print 'You have been defeated.'
  167. game_over()
  168. # do not need to define ring_desc() or fighter_desc() or whatever else I had intended on
  169. def fight_two():
  170. print '''You enter the ring again, and the crowd cheers you on. On the opposite end of the ring
  171. is your opponent, Wimpy HTML Dude. The referee signals the start of the fight, saying, "Fight!" '''
  172. # second break:
  173. # still need to complete def fight_two()
  174. # as well as all related functions
  175. # break taken 10/29/06 5:38 pm
  176. # will test then continue later
  177.  

Thank you all very much. I had hoped for this to remain on the d-L until I posted the finished project but I guess I am still to intermediate (if that) to do it on my own.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
mruane is offline Offline
76 posts
since Oct 2006
Oct 29th, 2006
0

Re: tribute project for daniweb

well, thats some interesting code you've got there, and quite a few errors indeed, but most seem to be simple.

for starters, you want the section at the top:
Python Syntax (Toggle Plain Text)
  1. print ''' TEXT KWON DO
  2. The ultimate text based martial arts tournament!
  3. Created especially for the many fine folks at
  4. www.daniweb.com's Python forum. '''
  5. print
  6. raw_input("Press Enter to continue: ")
  7. start()
  8.  
to go right at the bottom after EVERYTHING else, because if it's at the top, python doesn't know what the 'start()' command is, because it hasn't gotten to that section of the code yet.

after that, there are a few simple indentation errors, on lines 140 141, 166 and 167.

the function prompt_a() has the try, except thing in it, to catch errors that might come from the raw_input (a.k.a the user) great and useful as that is, it's also got the annoying effect of ignoring ("except: pass") any error thats in the rest of your program, so for the meantime i recomend removing the try, except and pass lines so that you can successefully debug your program.

Unfortunantly it's late where i am atm so i'm off to get some sleep.
If you get stuck again just post the problem, and peeps will give you a hand.

Enjoy,
a1eio
Last edited by a1eio; Oct 29th, 2006 at 9:14 pm.
Reputation Points: 26
Solved Threads: 24
Junior Poster
a1eio is offline Offline
140 posts
since Aug 2005
Oct 30th, 2006
0

Re: tribute project for daniweb

I don't have the time to show you the errors, but I ran it and found some easy fixes. Pull out your try and except statements like a1eio said. Then you'll see what's wrong. A couple main ones are:

- You didn't indent under some if/elif/else statements you needed to.

- move the start() to the bottom along with the intro print statements

- the program ends when I did this:

Python Syntax (Toggle Plain Text)
  1. Press enter to continue:
  2. You are about to enter the ring, soldier! Prepare yourself, do some push-ups,
  3. pull-ups, kick stuff, do some karate chops, throw a few fireballs (hint hint) and when
  4. you are ready, type 'start fight' to commence the beatings!
  5.  
  6. What do I do Sensai? start fight
  7. You are in the ring. Your opponent, C++ Punk, is on the opposite end of the ring.
  8. The referee yells "Fight!", and the battle commences. Type 'help' for a list of commands.
  9.  
  10. What do you do, Daniel San?punch
  11. >>>


More help later if you need it. I'm in a time crunch at the moment on a project and took a break.
Last edited by LaMouche; Oct 30th, 2006 at 12:22 am.
Featured Poster
Reputation Points: 83
Solved Threads: 39
Posting Whiz in Training
LaMouche is offline Offline
263 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Spell a String in reverse
Next Thread in Python Forum Timeline: Python - Card Class - Graphics Win





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC