944,089 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 5657
  • Python RSS
Oct 30th, 2006
0

RPG Battle Simulation

Expand Post »
Here is an example I was thinking of ...
python Syntax (Toggle Plain Text)
  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.
Similar Threads
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 31st, 2006
0

Re: RPG Battle Simulation

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?
Featured Poster
Reputation Points: 83
Solved Threads: 39
Posting Whiz in Training
LaMouche is offline Offline
263 posts
since Oct 2006
Nov 20th, 2009
-1
Re: RPG Battle Simulation
Click to Expand / Collapse  Quote originally posted by LaMouche ...
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...
Reputation Points: 17
Solved Threads: 2
Light Poster
python user is offline Offline
28 posts
since Nov 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: Renaming Files Help
Next Thread in Python Forum Timeline: RPG Battle Action





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


Follow us on Twitter


© 2011 DaniWeb® LLC