943,987 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 395942
  • Python RSS
You are currently viewing page 5 of this multi-page discussion thread; Jump to the first page
Mar 6th, 2009
0

Re: Python Game: Norbert Quest

The saved games should not change the code, but if you posted the file with the saved game in it, we should be able to save it and have the game load it like it was our saved game.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Mar 6th, 2009
0

Re: Python Game: Norbert Quest

Murtan I took your code with the mode inputs as functions and pimped it out a bit, but I can't figure this part out:
python Syntax (Toggle Plain Text)
  1. import random
  2. class NorbertQuest(object):
  3.  
  4. def __init__(self):
  5. self.weapon = 0
  6. self.armor = 0
  7. self.level = 1
  8. self.m = random.randrange(50)+1+self.level*5
  9. self.cost = 0
  10. self.xp = 0
  11. self.health = 150
  12. self.ehealth = 100
  13. self.money = 100
  14. self.tnls = [100+level*50]
  15. self.wepORshield = 0
  16. self.withdraw = 0
  17. self.deposit = 0
  18. self.bankbalance = 0
  19.  
  20. def Shop(self):
  21. self.weapons[1:"Steel Knuckles",2:"Knife",3:"Sword",4:"Gun",5:"Rocket Launcher"]
  22. self.armors[1:"Leather Jacket",2:"Padded Sweater",3:"Iron Arm-shield",4:"Bullet-Proof Jacket",5:"Bomber Squad Armor Plated Suit"]
  23. print \
  24. """
  25. What'll it be?
  26. Weapons:
  27. 1 - Steel Knuckles 50$
  28. 2 - Knife 75$
  29. 3 - Sword 300$
  30. 4 - Gun 800$
  31. 5 - Rocket Launcher 2500$
  32.  
  33. Armor:
  34. 1 - Leather Jacket 50$
  35. 2 - Padded Sweater 75$
  36. 3 - Iron Arm-shield 300$
  37. 4 - Bullet-Proof Jacket 800$
  38. 5 - Bomber Squad Armor Plated Suit
  39.  
  40. Type exit to quit.
  41. """
  42. self.wepORshield = raw_input("Do you want weapons or armor?")
  43. if self.wepORshield == "weapons":
  44. self.atk = input("Which weapon do you want?")
  45. if self.atk == 1:
  46. self.cost = 50
  47. if self.money >= self.cost:
  48. print"You have bought",self.weapons[self.atk]
  49. self.money = self.money - self.cost
  50. self.weapon = 1
  51. self.mode = "restart"
  52. elif self.money < self.cost:
  53. print"You don't have enough gold to buy this."
  54. raw_input("Press [enter] to exit.")
  55. self.mode = "restart"
  56. elif self.atk == 2:
  57. self.cost = 75
  58. if self.money >= self.cost:
  59. print"You have bought",self.weapons[self.atk]
  60. self.money = self.money - self.cost
  61. self.weapon = 2
  62. self.mode = "restart"
  63. elif self.money < self.cost:
  64. print"You don't have enough gold to buy this."
  65. raw_input("Press [enter] to exit.")
  66. self.mode = "restart"
  67. elif self.atk == 3:
  68. self.cost = 300
  69. if self.money >= self.cost:
  70. print"You have bought",self.weapons[self.atk]
  71. self.money = self.money - self.cost
  72. self.weapon = 3
  73. self.mode = "restart"
  74. elif self.money < self.cost:
  75. print"You don't have enough gold to buy this."
  76. raw_input("Press [enter] to exit.")
  77. self.mode = "restart"
  78. elif self.atk == 4:
  79. self.cost = 800
  80. if self.money >= self.cost:
  81. print"You have bought",self.weapons[self.atk]
  82. self.money = self.money - self.cost
  83. self.weapon = 4
  84. self.mode = "restart"
  85. elif self.money < self.cost:
  86. print"You don't have enough gold to buy this."
  87. raw_input("Press [enter] to exit.")
  88. self.mode = "restart"
  89. if self.atk == 5:
  90. self.cost = 2500
  91. if self.money >= self.cost:
  92. print"You have bought",self.weapons[self.atk]
  93. self.money = self.money - self.cost
  94. self.weapon = 5
  95. self.mode = "restart"
  96. elif self.money < self.cost:
  97. print"You don't have enough gold to buy this."
  98. raw_input("Press [enter] to exit.")
  99. self.mode = "restart"
  100.  
  101. elif wepORshield == "shield":
  102. if self.shield == 1:
  103. self.cost = 50
  104. if self.money >= self.cost:
  105. print"You have bought",self.armors[self.shield]
  106. self.money = self.money - self.cost
  107. self.armor = 1
  108. self.mode = "restart"
  109. elif self.money < self.cost:
  110. print"You don't have enough gold to buy this."
  111. raw_input("Press [enter] to exit.")
  112. self.mode = "restart"
  113. elif self.shield == 2:
  114. self.cost = 75
  115. if self.money >= self.cost:
  116. print"You have bought",self.armors[self.shield]
  117. self.money = self.money - self.cost
  118. self.armor = 2
  119. self.mode = "restart"
  120. elif self.money < self.cost:
  121. print"You don't have enough gold to buy this."
  122. raw_input("Press [enter] to exit.")
  123. self.mode = "restart"
  124. elif self.shield == 3:
  125. self.cost = 300
  126. if self.money >= self.cost:
  127. print"You have bought",self.armors[self.shield]
  128. self.money = self.money - self.cost
  129. self.armor = 3
  130. self.mode = "restart"
  131. elif self.money < self.cost:
  132. print"You don't have enough gold to buy this."
  133. raw_input("Press [enter] to exit.")
  134. self.mode = "restart"
  135. elif self.shield == 4:
  136. self.cost = 800
  137. if self.money >= self.cost:
  138. print"You have bought",self.armors[self.shield]
  139. self.money = self.money - self.cost
  140. self.armor = 4
  141. self.mode = "restart"
  142. elif self.money < self.cost:
  143. print"You don't have enough gold to buy this."
  144. raw_input("Press [enter] to exit.")
  145. self.mode = "restart"
  146. if self.shield == 5:
  147. self.cost = 2500
  148. if self.money >= self.cost:
  149. print"You have bought",self.armors[self.shield]
  150. self.money = self.money - self.cost
  151. self.armor = 5
  152. self.mode = "restart"
  153. elif self.money < self.cost:
  154. print"You don't have enough gold to buy this."
  155. raw_input("Press [enter] to exit.")
  156. self.mode = "restart"
  157. elif self.atk == "exit":
  158. self.mode = "restart"
  159.  
  160.  
  161. def eAttack(self):
  162. self.attacke = random.randrange(12)+self.level*12
  163. return self.attacke
  164.  
  165. def HP(self):
  166. self.e = self.eAttack()
  167. self.d = self.nDefense()
  168. self.health = self.health - (self.e - self.d)
  169. print "Enemy hits for",self.e
  170. print "You block for",self.d
  171. print "Your HP is",self.health
  172.  
  173. def nAttack(self):
  174. self.attack = random.randrange(10)+self.level*10
  175. if self.weapon == 1:
  176. self.attack = random.randrange(10)+35+self.level*10
  177. elif self.weapon == 2:
  178. self.attack = random.randrange(10)+55+self.level*10
  179. elif self.weapon == 3:
  180. self.attack = random.randrange(10)+90+self.level*10
  181. elif self.weapon == 4:
  182. self.attack = random.randrange(10)+150+self.level*10
  183. elif self.weapon == 5:
  184. self.attack = random.randrange(10)+340+self.level*10
  185. return self.attack
  186.  
  187. def nDefense(self):
  188. self.armor = random.randrange(5)+self.level*5
  189. if self.armor == 1:
  190. self.defense = random.randrange(5)+10+self.level*5
  191. if self.armor == 2:
  192. self.defense = random.randrange(5)+25+self.level*5
  193. if self.armor == 3:
  194. self.defense = random.randrange(5)+45+self.level*5
  195. if self.armor == 4:
  196. self.defense = random.randrange(5)+70+self.level*5
  197. if self.armor == 5:
  198. self.defense = random.randrange(5)+125+self.level*5
  199. return self.defense
  200.  
  201. def LVL(self):
  202. if 1 <= self.level <= len(self.tnls):
  203. self.tnl = self.tnls[self.level-1]
  204. if self.tnl <= self.xp:
  205. self.level += 1
  206. if self.level > len(self.tnls):
  207. self.level = 100
  208. self.xp = 0
  209. print("Your new level is %d! Congratulations!" % self.level)
  210. if self.level == 100:
  211. print("Congratulations, you beat the Demo!")
  212.  
  213. def EnemyHP(self):
  214. self.n = self.nAttack()
  215. self.ehealth = self.ehealth - self.n
  216. print "You hit for",self.n
  217. print "Enemy's HP is",self.ehealth
  218.  
  219.  
  220. def Bank(self):
  221. print"Welcome to the National Bank of NorbertQuest! What will you like to do?"
  222. self.bankchoice = raw_input("Do you want to withdraw or deposit? ")
  223. if self.bankchoice == "withdraw":
  224. print"Your current balance is",bankbalance,"dollars."
  225. self.withdraw = raw_input("How much would you like to withdraw? ")
  226. if self.withdraw > self.bankbalance:
  227. print"You don't have that much money in the bank!"
  228. self.mode = "restart"
  229. elif self.withdraw <= self.bankbalance:
  230. self.bankbalance - self.withdraw = self.money
  231. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  232. self.mode = "restart"
  233. elif self.bankchoice == "deposit":
  234. print"Your current balance is",bankbalance,"dollars."
  235. self.deposit = raw_input("How much would you like to deposit? ")
  236. if self.deposit > self.money:
  237. print"You don't have that much money on you!"
  238. self.mode = "restart"
  239. elif self.deposit <= self.money:
  240. self.money - self.deposit = self.bankbalance
  241. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  242. self.mode = "restart"
  243.  
  244. def Battle(self):
  245. self.fight = random.randrange(10)+1
  246. if self.fight == 1:
  247. self.monster = "Dragon!"
  248. elif self.fight == 2:
  249. self.monster = "Rogue Knight!"
  250. elif self.fight == 3:
  251. self.monster == "Jaguar!"
  252. elif self.fight == 4:
  253. self.monster = "Orc Lord!"
  254. elif self.fight == 5:
  255. self.monster = "Goblin!"
  256. elif self.fight == 6:
  257. self.monster = "Crazy Robot!"
  258. elif self.fight == 7:
  259. self.monster = "Werewolf!"
  260. elif self.fight == 8:
  261. self.monster = "Vampire!"
  262. elif self.fight == 9:
  263. self.monster = "Giant Spider!"
  264. elif self.fight == 10:
  265. self.monster = "Pirate King!"
  266.  
  267. print "You have encountered a", self.monster, "What will you do?"
  268. self.health = 150 + self.level * 100
  269. self.ehealth = 100 + self.level * 125
  270.  
  271. while self.health > 0 and self.ehealth > 0:
  272. self.turn = raw_input("Do you want to attack[1], defend[2] or cast a spell[coming soon]??")
  273.  
  274. if self.turn == 1:
  275. print "You're attacking!"
  276. self.EnemyHP()
  277. self.HP()
  278. elif self.turn == 2:
  279. print "You're defending!"
  280. print "Monster's HP is",self.ehealth
  281. print "Your HP is",self.health
  282. else:
  283. print "Type attack or Defend!"
  284.  
  285. if self.health <= 0:
  286. print "You are dead! You lose 50% of the money you have on you!"
  287. self.money = self.money/2
  288. elif self.ehealth <= 0:
  289. print "You win the battle! You earn",self.m,"$!"
  290. self.money = self.money + self.m
  291. self.m = random.randrange(50)+1+self.level*5
  292. self.xpGain = random.randrange(25)+self.level+25
  293. self.xp = self.xpGain + self.xp
  294. print"You gain",self.xpGain,"Experience Points!"
  295. self.LVL()
  296.  
  297. def main(self):
  298. while True:
  299. print \
  300. """
  301. Welcome to NorbertQuest!
  302. Type:
  303. - [battle] to hunt monsters
  304. - [shop] to buy weapons
  305. - [bank] to visit the bank
  306. - [badge] to visit the Government Building
  307. - [exit] to quit the game
  308.  
  309. """
  310. self.mode = raw_input("What do you want to do?: ")
  311. if self.mode == "shop":
  312. print"Your current weapon is",self.weapon[self.atk]
  313. print"Your current armor is",self.armor[self.shield]
  314. print"You have",money,"dollars on you."
  315. self.Shop()
  316.  
  317. elif self.mode == "battle":
  318. self.Battle()
  319.  
  320. elif self.mode == "badge":
  321. if self.level >= 10:
  322. print"Your current Government Rank is",self.govrank
  323. self.Badge()
  324. elif self.level < 10:
  325. print"Come back when you're stronger!"
  326. self.mode = "restart"
  327.  
  328. elif self.mode == "bank":
  329. self.Bank()
  330.  
  331. elif self.mode == "exit":
  332. print "If you exit now, all progress will be lost."
  333. self.exit = raw_input("Are you sure you want to quit? Yes or no: ")
  334. if "yes" in self.exit:
  335. break
  336. if "no" in self.exit:
  337. drlf.mode = "restart"
  338.  
  339.  
  340. if __name__ == "__main__":
  341. n = NorbertQuest()
  342. n.main()
  343.  
  344. raw_input("Press [enter] to exit.")

I added a bank function (because dying needs consequences and you lose half your money on you so the bank keeps it safe) and a guild-like function (the government) and as you level up. you get new ranks and you get 10% more gold or xp (or higher) as your government rank goes up: level 10-officer, level 25-knight, level 50 - captain, level 90 - guardian, level 150 - lord commishener (I've got absolutely no idea how to spell it), level 200-imperial officer. once the xp/money increase is 100% or whatever, your xp and money will be double the usual you'd get. also there are special weapons only a certain rank can use (though I've yet to add them).
Reputation Points: 52
Solved Threads: 0
Junior Poster in Training
Norbert X is offline Offline
87 posts
since Feb 2009
Mar 7th, 2009
1

Re: Python Game: Norbert Quest

If you're having a problem with part of the code, please be specific as to what the problem is. What did you see? What did you expect to see?

If it is a compile problem, include the full text of the compiler error if possible.

I saw something interesting in your new banking code, you ask for the amount to deposit/withdraw using raw_input. This alone is not a problem but it does mean that the amount is a string and not a number. You will need to convert it to a number before you attempt to compare against the balance or the cash-on-hand.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Mar 7th, 2009
0

Re: Python Game: Norbert Quest

In the bank function, it can't add the deposit into the bankbalance:
Python Syntax (Toggle Plain Text)
  1. elif self.deposit <= self.money:
  2. self.money - self.deposit = self.bankbalance
  3. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  4. self.mode = "restart"
Last edited by Norbert X; Mar 7th, 2009 at 3:37 pm.
Reputation Points: 52
Solved Threads: 0
Junior Poster in Training
Norbert X is offline Offline
87 posts
since Feb 2009
Mar 7th, 2009
0

Re: Python Game: Norbert Quest

Python Syntax (Toggle Plain Text)
  1. *** can't assign to operator (NQv1, line 241)
  2.  

That's the error I get. Line 241 is the self.money - self.deposit = self.bankbalance in my previous post.
Reputation Points: 52
Solved Threads: 0
Junior Poster in Training
Norbert X is offline Offline
87 posts
since Feb 2009
Mar 7th, 2009
1

Re: Python Game: Norbert Quest

This is the problem:
python Syntax (Toggle Plain Text)
  1. self.money - self.deposit = self.bankbalance
Change it to this
python Syntax (Toggle Plain Text)
  1. self.bankbalance = self.money - self.deposit
Your operations always have to be on the Right side of the "=" sign
Reputation Points: 264
Solved Threads: 183
Veteran Poster
Paul Thompson is offline Offline
1,095 posts
since May 2008
Mar 7th, 2009
0

Re: Python Game: Norbert Quest

Thanks I never thought of that.
Reputation Points: 52
Solved Threads: 0
Junior Poster in Training
Norbert X is offline Offline
87 posts
since Feb 2009
Mar 7th, 2009
0

Re: Python Game: Norbert Quest

Ok now I have 2 more problems: My money disappears if I deposit it into the bank (you start off with 100 dollars) and also I don't know how to define self.atk:
Python Syntax (Toggle Plain Text)
  1. import random
  2. class NorbertQuest(object):
  3.  
  4. def __init__(self):
  5. self.weapon = 0
  6. self.armor = 0
  7. self.level = 1
  8. self.m = random.randrange(50)+1+self.level*5
  9. self.cost = 0
  10. self.xp = 0
  11. self.health = 150
  12. self.ehealth = 100
  13. self.money = 100
  14. self.tnls = [100+self.level*50]
  15. self.wepORshield = 0
  16. self.bankbalance = 0
  17. self.withdraw = 0
  18. self.deposit = 0
  19.  
  20.  
  21. def Shop(self):
  22. self.weapons[1:"Steel Knuckles",2:"Knife",3:"Sword",4:"Gun",5:"Rocket Launcher"]
  23. self.armors[1:"Leather Jacket",2:"Padded Sweater",3:"Iron Arm-shield",4:"Bullet-Proof Jacket",5:"Bomber Squad Armor Plated Suit"]
  24. print \
  25. """
  26. What'll it be?
  27. Weapons:
  28. 1 - Steel Knuckles 50$
  29. 2 - Knife 75$
  30. 3 - Sword 300$
  31. 4 - Gun 800$
  32. 5 - Rocket Launcher 2500$
  33.  
  34. Armor:
  35. 1 - Leather Jacket 50$
  36. 2 - Padded Sweater 75$
  37. 3 - Iron Arm-shield 300$
  38. 4 - Bullet-Proof Jacket 800$
  39. 5 - Bomber Squad Armor Plated Suit
  40.  
  41. Type exit to quit.
  42. """
  43. self.wepORshield = raw_input("Do you want weapons or armor?")
  44. if self.wepORshield == "weapons":
  45. self.atk = input("Which weapon do you want?")
  46. if self.atk == 1:
  47. self.cost = 50
  48. if self.money >= self.cost:
  49. print"You have bought",self.weapons[self.atk]
  50. self.money = self.money - self.cost
  51. self.weapon = 1
  52. self.mode = "restart"
  53. elif self.money < self.cost:
  54. print"You don't have enough gold to buy this."
  55. raw_input("Press [enter] to exit.")
  56. self.mode = "restart"
  57. elif self.atk == 2:
  58. self.cost = 75
  59. if self.money >= self.cost:
  60. print"You have bought",self.weapons[self.atk]
  61. self.money = self.money - self.cost
  62. self.weapon = 2
  63. self.mode = "restart"
  64. elif self.money < self.cost:
  65. print"You don't have enough gold to buy this."
  66. raw_input("Press [enter] to exit.")
  67. self.mode = "restart"
  68. elif self.atk == 3:
  69. self.cost = 300
  70. if self.money >= self.cost:
  71. print"You have bought",self.weapons[self.atk]
  72. self.money = self.money - self.cost
  73. self.weapon = 3
  74. self.mode = "restart"
  75. elif self.money < self.cost:
  76. print"You don't have enough gold to buy this."
  77. raw_input("Press [enter] to exit.")
  78. self.mode = "restart"
  79. elif self.atk == 4:
  80. self.cost = 800
  81. if self.money >= self.cost:
  82. print"You have bought",self.weapons[self.atk]
  83. self.money = self.money - self.cost
  84. self.weapon = 4
  85. self.mode = "restart"
  86. elif self.money < self.cost:
  87. print"You don't have enough gold to buy this."
  88. raw_input("Press [enter] to exit.")
  89. self.mode = "restart"
  90. if self.atk == 5:
  91. self.cost = 2500
  92. if self.money >= self.cost:
  93. print"You have bought",self.weapons[self.atk]
  94. self.money = self.money - self.cost
  95. self.weapon = 5
  96. self.mode = "restart"
  97. elif self.money < self.cost:
  98. print"You don't have enough gold to buy this."
  99. raw_input("Press [enter] to exit.")
  100. self.mode = "restart"
  101.  
  102. elif wepORshield == "shield":
  103. if self.shield == 1:
  104. self.cost = 50
  105. if self.money >= self.cost:
  106. print"You have bought",self.armors[self.shield]
  107. self.money = self.money - self.cost
  108. self.armor = 1
  109. self.mode = "restart"
  110. elif self.money < self.cost:
  111. print"You don't have enough gold to buy this."
  112. raw_input("Press [enter] to exit.")
  113. self.mode = "restart"
  114. elif self.shield == 2:
  115. self.cost = 75
  116. if self.money >= self.cost:
  117. print"You have bought",self.armors[self.shield]
  118. self.money = self.money - self.cost
  119. self.armor = 2
  120. self.mode = "restart"
  121. elif self.money < self.cost:
  122. print"You don't have enough gold to buy this."
  123. raw_input("Press [enter] to exit.")
  124. self.mode = "restart"
  125. elif self.shield == 3:
  126. self.cost = 300
  127. if self.money >= self.cost:
  128. print"You have bought",self.armors[self.shield]
  129. self.money = self.money - self.cost
  130. self.armor = 3
  131. self.mode = "restart"
  132. elif self.money < self.cost:
  133. print"You don't have enough gold to buy this."
  134. raw_input("Press [enter] to exit.")
  135. self.mode = "restart"
  136. elif self.shield == 4:
  137. self.cost = 800
  138. if self.money >= self.cost:
  139. print"You have bought",self.armors[self.shield]
  140. self.money = self.money - self.cost
  141. self.armor = 4
  142. self.mode = "restart"
  143. elif self.money < self.cost:
  144. print"You don't have enough gold to buy this."
  145. raw_input("Press [enter] to exit.")
  146. self.mode = "restart"
  147. if self.shield == 5:
  148. self.cost = 2500
  149. if self.money >= self.cost:
  150. print"You have bought",self.armors[self.shield]
  151. self.money = self.money - self.cost
  152. self.armor = 5
  153. self.mode = "restart"
  154. elif self.money < self.cost:
  155. print"You don't have enough gold to buy this."
  156. raw_input("Press [enter] to exit.")
  157. self.mode = "restart"
  158. elif self.atk == "exit":
  159. self.mode = "restart"
  160.  
  161.  
  162. def eAttack(self):
  163. self.attacke = random.randrange(12)+self.level*12
  164. return self.attacke
  165.  
  166. def HP(self):
  167. self.e = self.eAttack()
  168. self.d = self.nDefense()
  169. self.health = self.health - (self.e - self.d)
  170. print "Enemy hits for",self.e
  171. print "You block for",self.d
  172. print "Your HP is",self.health
  173.  
  174. def nAttack(self):
  175. self.attack = random.randrange(10)+self.level*10
  176. if self.weapon == 1:
  177. self.attack = random.randrange(10)+35+self.level*10
  178. elif self.weapon == 2:
  179. self.attack = random.randrange(10)+55+self.level*10
  180. elif self.weapon == 3:
  181. self.attack = random.randrange(10)+90+self.level*10
  182. elif self.weapon == 4:
  183. self.attack = random.randrange(10)+150+self.level*10
  184. elif self.weapon == 5:
  185. self.attack = random.randrange(10)+340+self.level*10
  186. return self.attack
  187.  
  188. def nDefense(self):
  189. self.armor = random.randrange(5)+self.level*5
  190. if self.armor == 1:
  191. self.defense = random.randrange(5)+10+self.level*5
  192. if self.armor == 2:
  193. self.defense = random.randrange(5)+25+self.level*5
  194. if self.armor == 3:
  195. self.defense = random.randrange(5)+45+self.level*5
  196. if self.armor == 4:
  197. self.defense = random.randrange(5)+70+self.level*5
  198. if self.armor == 5:
  199. self.defense = random.randrange(5)+125+self.level*5
  200. return self.defense
  201.  
  202. def LVL(self):
  203. if 1 <= self.level <= len(self.tnls):
  204. self.tnl = self.tnls[self.level-1]
  205. if self.tnl <= self.xp:
  206. self.level += 1
  207. if self.level > len(self.tnls):
  208. self.level = 100
  209. self.xp = 0
  210. print("Your new level is %d! Congratulations!" % self.level)
  211. if self.level == 100:
  212. print("Congratulations, you beat the Demo!")
  213.  
  214. def EnemyHP(self):
  215. self.n = self.nAttack()
  216. self.ehealth = self.ehealth - self.n
  217. print "You hit for",self.n
  218. print "Enemy's HP is",self.ehealth
  219.  
  220.  
  221. def Bank(self):
  222. print"Welcome to the National Bank of NorbertQuest! What will you like to do?"
  223. self.bankchoice = raw_input("Do you want to withdraw or deposit? ")
  224. if self.bankchoice == "withdraw":
  225. print"Your current balance is",self.bankbalance,"dollars."
  226. self.withdraw = input("How much would you like to withdraw? ")
  227. if self.withdraw > self.bankbalance:
  228. print"You don't have that much money in the bank!"
  229. self.mode = "restart"
  230. elif self.withdraw <= self.bankbalance:
  231. self.money = self.bankbalance - self.withdraw
  232. self.bankbalance = self.bankbalance - self.withdraw
  233. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  234. self.mode = "restart"
  235. elif self.bankchoice == "deposit":
  236. print"Your current balance is",self.bankbalance,"dollars."
  237. self.deposit = input("How much would you like to deposit? ")
  238. if self.deposit > self.money:
  239. print"You don't have that much money on you!"
  240. self.mode = "restart"
  241. elif self.deposit <= self.money:
  242. self.bankbalance = self.money - self.deposit
  243. self.money = self.money - self.deposit
  244. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  245. self.mode = "restart"
  246.  
  247. def Battle(self):
  248. self.fight = random.randrange(10)+1
  249. if self.fight == 1:
  250. self.monster = "Dragon!"
  251. elif self.fight == 2:
  252. self.monster = "Rogue Knight!"
  253. elif self.fight == 3:
  254. self.monster == "Jaguar!"
  255. elif self.fight == 4:
  256. self.monster = "Orc Lord!"
  257. elif self.fight == 5:
  258. self.monster = "Goblin!"
  259. elif self.fight == 6:
  260. self.monster = "Crazy Robot!"
  261. elif self.fight == 7:
  262. self.monster = "Werewolf!"
  263. elif self.fight == 8:
  264. self.monster = "Vampire!"
  265. elif self.fight == 9:
  266. self.monster = "Giant Spider!"
  267. elif self.fight == 10:
  268. self.monster = "Pirate King!"
  269.  
  270. print "You have encountered a", self.monster, "What will you do?"
  271. self.health = 150 + self.level * 100
  272. self.ehealth = 100 + self.level * 125
  273.  
  274. while self.health > 0 and self.ehealth > 0:
  275. self.turn = raw_input("Do you want to attack[1], defend[2] or cast a spell[coming soon]?")
  276.  
  277. if self.turn == 1:
  278. print "You're attacking!"
  279. self.EnemyHP()
  280. self.HP()
  281. elif self.turn == 2:
  282. print "You're defending!"
  283. print "Monster's HP is",self.ehealth
  284. print "Your HP is",self.health
  285. else:
  286. print "Type attack or Defend!"
  287.  
  288. if self.health <= 0:
  289. print "You are dead! You lose 50% of the money you have on you!"
  290. self.money = self.money/2
  291. elif self.ehealth <= 0:
  292. print "You win the battle! You earn",self.m,"$!"
  293. self.money = self.money + self.m
  294. self.m = random.randrange(50)+1+self.level*10
  295. self.xpGain = random.randrange(25)+1+self.level*25
  296. self.xp = self.xpGain + self.xp
  297. print"You gain",self.xpGain,"Experience Points!"
  298. self.LVL()
  299.  
  300. def main(self):
  301. while True:
  302. print \
  303. """
  304. Welcome to NorbertQuest!
  305. Type:
  306. - [battle] to hunt monsters
  307. - [shop] to buy weapons
  308. - [bank] to visit the bank
  309. - [badge] to visit the Government Building
  310. - [exit] to quit the game
  311.  
  312. """
  313. self.mode = raw_input("What do you want to do?: ")
  314. if self.mode == "shop":
  315. print"Your current weapon is",self.weapon[self.atk]
  316. print"Your current armor is",self.armor[self.shield]
  317. print"You have",money,"dollars on you."
  318. self.Shop()
  319.  
  320. elif self.mode == "battle":
  321. self.Battle()
  322.  
  323. elif self.mode == "badge":
  324. if self.level >= 10:
  325. print"Your current Government Rank is",self.govrank
  326. self.Badge()
  327. elif self.level < 10:
  328. print"Come back when you're stronger!"
  329. self.mode = "restart"
  330.  
  331. elif self.mode == "bank":
  332. self.Bank()
  333.  
  334. elif self.mode == "exit":
  335. print "If you exit now, all progress will be lost."
  336. self.exit = raw_input("Are you sure you want to quit? Yes or no: ")
  337. if "yes" in self.exit:
  338. break
  339. if "no" in self.exit:
  340. drlf.mode = "restart"
  341.  
  342.  
  343. if __name__ == "__main__":
  344. n = NorbertQuest()
  345. n.main()
  346.  
  347. raw_input("Press [enter] to exit.")

And can someone help me with the Government Function (well Badge Function)? I don't know how to go at it. If you don't know what the government is, look the last thing I posted with a code in it, and if that doesn't explain it, ask me.
Reputation Points: 52
Solved Threads: 0
Junior Poster in Training
Norbert X is offline Offline
87 posts
since Feb 2009
Mar 7th, 2009
0

Re: Python Game: Norbert Quest

Line 242 (line 2 in the fragment):

python Syntax (Toggle Plain Text)
  1. elif self.deposit <= self.money:
  2. self.bankbalance = self.money - self.deposit
  3. self.money = self.money - self.deposit
  4. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  5. self.mode = "restart"

When depositing to the bank, we need to increase the bank balance and decrease the gold:
python Syntax (Toggle Plain Text)
  1. self.bankbalance = self.bankbalance + self.deposit
  2. self.money = self.money - self.deposit


You have a similar problem in withdraw:
python Syntax (Toggle Plain Text)
  1. elif self.withdraw <= self.bankbalance:
  2. self.money = self.bankbalance - self.withdraw
  3. self.bankbalance = self.bankbalance - self.withdraw
  4. print"Your new bank Balance is",self.bankbalance,"dollars. Thank you."
  5. self.mode = "restart"

When withdrawing, we need to increase our money and decrease the bank balance:
python Syntax (Toggle Plain Text)
  1. self.money = self.money + self.withdraw
  2. self.bankbalance = self.bankbalance - self.withdraw
Last edited by Murtan; Mar 7th, 2009 at 9:29 pm.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Mar 8th, 2009
0

Re: Python Game: Norbert Quest

Thanks, and for the ATK variable, did I just need to include it in the beginning with the self.variable?
Reputation Points: 52
Solved Threads: 0
Junior Poster in Training
Norbert X is offline Offline
87 posts
since Feb 2009

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: Ejecting trays of CDs
Next Thread in Python Forum Timeline: Looping through and removing parts of a list





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


Follow us on Twitter


© 2011 DaniWeb® LLC