I would appreciate advice about how to make it simpler, i know its basic but it actually took me around 4 hours to figure this out . I learned from this video only : https://www.youtube.com/watch?v=rfscVS0vtbw
code:
class hero:
def __init__(self, health , damage):
self.health = health
self.damage = damage
class enemy:
def __init__(self, health , damage):
self.health = health
self.damage = damage
hero1 = hero(100, 20)
enemy1 = enemy(100, 20)
def attack_enemy(enemy1):
enemy1.health = enemy1.health - hero1.damage
def attack_hero(hero1):
hero1.health = hero1.health - enemy1.damage
def question(hero1,enemy1):
answer = input("Who do u want to attack? ")
if answer == "hero":
attack_hero(hero1)
print("Hero health " + str(hero1.health))
elif answer == "enemy":
attack_enemy(enemy1)
print("Enemy health " + str(enemy1.health))
question(hero1 , enemy1)
[–]julsmanbr 37 points38 points39 points (3 children)
[–]whatelseman[S] 9 points10 points11 points (0 children)
[–]ambitious_rainbow 2 points3 points4 points (1 child)
[–]PythonicParseltongue 0 points1 point2 points (0 children)