I am trying to get a game from exercise 36 in LPTHW to work.
I can get the whole part of the game working except when it gets to the combat. Here is where I think the problem is.
def combat_engine():
global wins, hit_points, current_hp
if monster_current_hp or current_hp > 0:
print "You can type 'a' for attack, or 'q' for quit, choose one."
answer = raw_input(":> ")
if 'a' in answer:
attack(monster)
attack('player')
combat_engine()
elif 'q' in answer:
print t.white_on_red("You give up and are devoured by the %s.") % monster
exit(0)
else:
print "I dont understand %s." % answer
next()
combat_engine()
elif monster_hp == 0:
print "You defeated the %s, congradulations %s!" % monster, name
wins = wins + 1
if wins == 5:
you_win()
elif victim == 'player':
hit_points = hit_points + d6()
current_hp = hit_points
print "You feel hardier."
next()
barracks()
elif current_hp == 0:
print "You have been deafeted by the %s, better luck next time." % monster
next()
exit(0)
else:
print "Bug Somewhere"
I believe the bug is somewhere in this function. When i printed out the HP values of each character, the battle was still going on after the monster had been reduced to -2 hp. maybe it a problem with booleans?
What I would like it to do is to either do all the stat adjustments for winning and quit the game if you lose. I just want to get past this so I can start learning about classes and dicts which should make my life much easier. Please let me know if I should post more information, I’m new at this and not the best at posting questions on here yet.
Thanks in advance!
in the last part of your code you don’t call the function d100(), but the value d100. That’s surely not what you want to do.
when debugging in python, the main word is “print”. You should feel free to print as much as possible so as to understand what’s going on.
example:
do the same in the combat engine so as to see the infinite loop appear. Then remove the useless print that bloat your trace with unuseful information, until you see clearly the reason it loops, because of some value, because of a boolean if test that doesn’t behave the way you expected… something like that.