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.

Member Avatar for Mouche

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?

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...

commented: why? +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.