karimruan
December 4th, 2009, 03:09 AM
I am writing a game for ubuntu (in python). It is a console game. I am having two problems.
When during battles the code is supposed to print the updated HP and enemy HP to the console. It prints, but never changes, it always stays to points below the max HP for the enemy. I really think the battle code needs redone, so any help with that would be nice. I used the battle code from Adventure.py from the forums.
Second, when in the function prompt1() if you 'look', 'take gold' and then 'look' again, it takes you back to the Troll battle ( level4() ). Not sure why. Anyways, thanks a bunch for the help.
here is the code for the battles:
def level4():
os.system("clear")
global gold
charhealth = 20
trollhealth = 20
print "You are faced with a Troll."
print
print \
"""
[]++++++[]
| TROLL |
[]++++++[]
YOUR HEALTH TROLL HEALTH
=========== ==========
20 HP 20 HP
"""
while (charhealth > 0) and (trollhealth > 0):
# Player attacks
chardmg = random.randrange(5) + 1
print "You attack the troll with your sword..."
print "You attack the troll for", chardmg, "damage!"
trollhealth -= chardmg
print "HP: ", charhealth
print "TROLL HP: ", trollhealth
raw_input()
# TROLL attacks
trolldmg = random.randrange(5) + 1
print "The TROLL attacks you for", trolldmg, "damage!"
charhealth -= trolldmg
print "HP: ", charhealth
print "TROLL HP: ", trollhealth
raw_input()
if charhealth < 0:
print "\nThe TROLL destroyed you!"
print 'You have lost.'
gameover()
else:
print "You killed the TROLL!"
gold_earn = random.randrange(8, 16)
print "You earned ", gold_earn, "Gold!\n"
gold += gold_earn
raw_input()
dungeon1()
I am also attaching the entire source to help with the problem with the look, take gold, look again problem.
When during battles the code is supposed to print the updated HP and enemy HP to the console. It prints, but never changes, it always stays to points below the max HP for the enemy. I really think the battle code needs redone, so any help with that would be nice. I used the battle code from Adventure.py from the forums.
Second, when in the function prompt1() if you 'look', 'take gold' and then 'look' again, it takes you back to the Troll battle ( level4() ). Not sure why. Anyways, thanks a bunch for the help.
here is the code for the battles:
def level4():
os.system("clear")
global gold
charhealth = 20
trollhealth = 20
print "You are faced with a Troll."
print \
"""
[]++++++[]
| TROLL |
[]++++++[]
YOUR HEALTH TROLL HEALTH
=========== ==========
20 HP 20 HP
"""
while (charhealth > 0) and (trollhealth > 0):
# Player attacks
chardmg = random.randrange(5) + 1
print "You attack the troll with your sword..."
print "You attack the troll for", chardmg, "damage!"
trollhealth -= chardmg
print "HP: ", charhealth
print "TROLL HP: ", trollhealth
raw_input()
# TROLL attacks
trolldmg = random.randrange(5) + 1
print "The TROLL attacks you for", trolldmg, "damage!"
charhealth -= trolldmg
print "HP: ", charhealth
print "TROLL HP: ", trollhealth
raw_input()
if charhealth < 0:
print "\nThe TROLL destroyed you!"
print 'You have lost.'
gameover()
else:
print "You killed the TROLL!"
gold_earn = random.randrange(8, 16)
print "You earned ", gold_earn, "Gold!\n"
gold += gold_earn
raw_input()
dungeon1()
I am also attaching the entire source to help with the problem with the look, take gold, look again problem.