DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   RPG Battle Simulation (http://www.daniweb.com/forums/thread59965.html)

vegaseat Oct 30th, 2006 11:07 pm
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.

LaMouche Oct 31st, 2006 12:49 am
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?

python user Nov 20th, 2009 10:32 am
Quote:

Originally Posted by LaMouche (Post 270125)
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...


All times are GMT -4. The time now is 3:14 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC