I know I already posted earlier, but I forgot to mention some things.
What I am trying to fix is a problem with the health tracking. When I run this code and attack, it subtracts a number (2-8) from eHP (20). The standalone print statements afterprint ("You dealt " + damage + " damage") andpy x = damage(eHP) show the right number (12-18). However, the py print (enemy + " " + eHP + "/20 HP") line shows 20/20, reverting eHP to 20. I know the eHP = 20 reverts it, but I don't know how to have it turn off once the damage calculation changes eHP.
I don't know how to fix this and need help
import random
import time
def banditcombat(MCHP):
enemy = "Bandit"
eHP = 20
print ("Suddenly, a bandit jumps from the bushes")
print ("What will you do?")
print (" ")
check = 1
turn(check, MCHP, eHP, MC, enemy)
print ("hi")
def turn (check, MCHP, eHP, MC, enemy):
turn2(check, MCHP, eHP, MC, enemy)
def turn2(check, MCHP, eHP, MC, enemy):
MCHP = str(MCHP)
eHP = str(eHP)
print (MC + " " + MCHP + "/50 HP")
print (enemy + " " + eHP + "/20 HP")
print (" Attack Heal")
turn3(check, MCHP, eHP, MC, enemy)
eHP = int(eHP)
if eHP <= 0:
return
else:
turn2(check, MCHP, eHP, MC, enemy)
return eHP
def turn3(check, MCHP, eHP, MC, enemy):
combat1 = input()
if combat1 == "attack" or combat1 == "Attack":
x = damage(eHP)
print (eHP)
check = 2
if combat1 == "heal" or combat1 == "Heal":
heal()
check = 2
if check == 1:
print("Invalid answer. Try again")
turn2(check, MCHP, eHP, MC, enemy)
return eHP
def damage(eHP):
damage = random.randint (2, 8)
damage = str(damage)
print ("You dealt " + damage + " damage")
eHP = int(eHP)
damage = int(damage)
eHP = eHP - damage
damage = str(damage)
print (eHP)
return eHP
def heal():
heal = random.randint (1, 4)
heal = str(heal)
print ("You recovered " + heal + " health")
MC = "Glorbo McFlorbo"
MCHP = 50
start = 1
banditcombat(MCHP)
print ("spots")
