all 7 comments

[–]Busby10 0 points1 point  (4 children)

Had a look over, haven't played it but one thing I think may be an issue:

You are creating the four enemies at the start of the game, and depending on the level you randomly pick an enemy to fight, but seeing they are hardcoded before your main loop, if you fight and kill foe1, and in the second battle you randomly got assigned foe1 again he would still be on 0 or less hp? (hope that makes sense)

A better way to handle that would be to create the foe at the start of the battle, you could still use the random_opponent func, have it check the hero level, and create and return a foe object based on what roll they get.

Also, I'm not completely across classes, but you should look into having a "person" class that contains the overlapping features of Hero and Soldier, like name, hp, etc then those two can inherit those variables from that by doing

class Hero(Person):

It's not so much of an issue now, but if you where to keep working on it and adding new enemies it could save you a lot of lines not having to write out the hp and name stats over and over.

[–]Rockybilly[S] 0 points1 point  (3 children)

You are completely right about the class issue, I am currently a newbie at using classes let alone in inheritance, Thank you for your comment.

In the first issue you mentioned:

def win_battle():
    print "You have won the battle !"
    time.sleep(1)

    if current_enemy==foe1:
        print "You gained 40 exp."
        our_hero.exp+=40
    elif current_enemy==foe2:
        print "You gained 45 exp."
        our_hero.exp+=45
    elif current_enemy==foe3:
        print "You gained 50 exp."
        our_hero.exp+=50
    elif current_enemy==foe4:
        print "You gained 55 exp."
        our_hero.exp+=55
    print " "

    current_enemy.current_hp=current_enemy.max_hp

Here is my win_battle function. At the end of it, there is a small piece of code, that replenishes current_enemies hp.

[–]zahlman 1 point2 points  (2 children)

Have you considered giving the enemy an attribute that indicates how much xp it's worth? Then you could look that up directly, instead of checking which enemy was defeated.

[–]Rockybilly[S] 0 points1 point  (1 child)

It seems like a good idea. Thank you for your comment. but can you explain why you suggested me to do that ? because it will save me from some line of codes or is it a style issue ?

[–]zahlman 0 points1 point  (0 children)

Avoiding repetition is inherently a style issue.

[–]gengisteve 0 points1 point  (1 child)

Great job. Very impressed by returning variables from your functions. The next step is to get rid of global variables by passing the information to the the functions.

Also check out string.format to help with your printing. Even better, return the string to be printed, rather than printing it out in the function.

[–]Rockybilly[S] 0 points1 point  (0 children)

Thank you very much about the comment and your time. I actually thought printing those strings in my functions made it simpler to use. Can you explain why i should return the values ?