RPG Battle Simulation

Reply

Join Date: Oct 2004
Posts: 3,946
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 913
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

RPG Battle Simulation

 
0
  #1
Oct 30th, 2006
Here is an example I was thinking of ...
  1. import random
  2. import time
  3.  
  4. def delay(seconds):
  5. time.sleep(seconds)
  6.  
  7. def shuffle_hitlists(my_hitlist, mo_hitlist):
  8. """shuffle the two lists and return the result"""
  9. random.shuffle(my_hitlist)
  10. random.shuffle(mo_hitlist)
  11. return my_hitlist, mo_hitlist
  12.  
  13. def battle(my_hitlist, mo_hitlist, my_strength, mo_strength):
  14. # player starts swinging first
  15. for k in range(len(my_hitlist)):
  16. my_hit = my_hitlist[k]
  17. mo_hit = mo_hitlist[k]
  18. # your turn
  19. if my_hit == 1:
  20. print "Scratched him good!"
  21. mo_strength -= 1
  22. elif my_hit == 2:
  23. print "Sliced him deep! Blood and guts!"
  24. mo_strength -= 2
  25. elif my_hit == 3:
  26. print "Excellent hit! He is screaming with pain!"
  27. mo_strength -= 3
  28. else: # my_hit == 0:
  29. print "You missed!"
  30. if mo_strength <= 0:
  31. print "The monster is dead!"
  32. break
  33. delay(2)
  34. # monster's turn
  35. if mo_hit == 1:
  36. print "You got scratched! It will heal quickly!"
  37. my_strength -= 1
  38. elif mo_hit == 2:
  39. print "Ouch, received a deep slice!"
  40. my_strength -= 2
  41. elif mo_hit == 3:
  42. print "You are hit and in pain! Loosing blood!"
  43. my_strength -= 3
  44. else: # mo_hit == 0
  45. print "The monster missed!"
  46. delay(2)
  47. print
  48. if my_strength < 5:
  49. print "You are weak and wounded, better withdraw!"
  50. break
  51.  
  52. if mo_strength > 0:
  53. print "The fleeing monster's strength is down to", mo_strength
  54. print "You still have a strength of", my_strength
  55.  
  56. my_hitlist = [1, 0, 2, 1, 3, 0, 3, 1]
  57. mo_hitlist = [1, 0, 2, 0, 3, 0, 1, 1]
  58.  
  59. my_strength = 20
  60. mo_strength = 10
  61.  
  62. my_hitlist, mo_hitlist = shuffle_hitlists(my_hitlist, mo_hitlist)
  63.  
  64. print my_hitlist, '\n', mo_hitlist # test
  65.  
  66. battle(my_hitlist, mo_hitlist, my_strength, mo_strength)
Need to improve the battle descriptions, maybe draw on a sentence lists with random.choice() to get some variety in there.

One could change the my_hitlist depending on the weapon carried, or change the mo_hitlist depending on the nastiness of the monster.

If you carry fancy armor the hits could be deminished in severity.

Let me know what you think.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 128
Reputation: LaMouche is on a distinguished road 
Solved Threads: 19
LaMouche's Avatar
LaMouche LaMouche is offline Offline
Junior Poster

Re: RPG Battle Simulation

 
0
  #2
Oct 31st, 2006
That's a good idea. I'm curious how turn-based games when you fight a monster work. I'm guessing no one here has worked on that sort of thing. =\

The hitlist type thing just doesn't seem like a great way to do it. I guess you could cycle it if the program hit the end of it, but I don't know... hmmm.

Thoughts from others?
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 22
Reputation: python user is an unknown quantity at this point 
Solved Threads: 0
python user's Avatar
python user python user is offline Offline
Newbie Poster
 
-1
  #3
2 Days Ago
Originally Posted by LaMouche View Post
That's a good idea. I'm curious how turn-based games when you fight a monster work. I'm guessing no one here has worked on that sort of thing. =\

The hitlist type thing just doesn't seem like a great way to do it. I guess you could cycle it if the program hit the end of it, but I don't know... hmmm.

Thoughts from others?
interesting...
If at first you don't succeed... run the code again.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC