RPG Battle Simulation
Here is an example I was thinking of ...
import random
import time
def delay(seconds):
time.sleep(seconds)
def shuffle_hitlists(my_hitlist, mo_hitlist):
"""shuffle the two lists and return the result"""
random.shuffle(my_hitlist)
random.shuffle(mo_hitlist)
return my_hitlist, mo_hitlist
def battle(my_hitlist, mo_hitlist, my_strength, mo_strength):
# player starts swinging first
for k in range(len(my_hitlist)):
my_hit = my_hitlist[k]
mo_hit = mo_hitlist[k]
# your turn
if my_hit == 1:
print "Scratched him good!"
mo_strength -= 1
elif my_hit == 2:
print "Sliced him deep! Blood and guts!"
mo_strength -= 2
elif my_hit == 3:
print "Excellent hit! He is screaming with pain!"
mo_strength -= 3
else: # my_hit == 0:
print "You missed!"
if mo_strength <= 0:
print "The monster is dead!"
break
delay(2)
# monster's turn
if mo_hit == 1:
print "You got scratched! It will heal quickly!"
my_strength -= 1
elif mo_hit == 2:
print "Ouch, received a deep slice!"
my_strength -= 2
elif mo_hit == 3:
print "You are hit and in pain! Loosing blood!"
my_strength -= 3
else: # mo_hit == 0
print "The monster missed!"
delay(2)
print
if my_strength < 5:
print "You are weak and wounded, better withdraw!"
break
if mo_strength > 0:
print "The fleeing monster's strength is down to", mo_strength
print "You still have a strength of", my_strength
my_hitlist = [1, 0, 2, 1, 3, 0, 3, 1]
mo_hitlist = [1, 0, 2, 0, 3, 0, 1, 1]
my_strength = 20
mo_strength = 10
my_hitlist, mo_hitlist = shuffle_hitlists(my_hitlist, mo_hitlist)
print my_hitlist, '\n', mo_hitlist # test
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.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417