Updated 2022-05-21 0
Viewed 5 times
0

My program's output should be the player health - damage. It does display the right number, but the number displayed in the terminal is negative. I set the player health to be 100, so if the player took 39 damage it would display -61 (39 + 61 = 100).

import random

class player():
    def __init__(self, player_name = "sus", player_health = 1, player_str = 1, player_speed = 1, player_mana = 1, player_bonus = 1):
        self.player_name = player_name
        self.player_health = player_health
        self.player_str = player_str
        self.player_speed = player_speed
        self.player_mana = player_mana
        self.player_bonus = player_bonus

class enemy:
    def __init__(self, name = 'creature', health = 10, speed = 10, strenght = 10, mana = 10):
        self.name = name
        self.health = health
        self.speed = speed
        self.mana = mana
        self.strenght = strenght
        if name == "goblin":
            self.goblin()
            self.strenght_attack()
        elif name == "golem":
            self.golem()
            self.strenght_attack()

    def golem(self, name = "golem", health = 150, speed = 23, strenght = 50, mana = 0):
        self.name = name
        self.mana = mana
        self.health = health
        self.speed = speed
        self.strenght = strenght

    def goblin(self, name = "goblin", health = 40, speed = 60, strenght = 14, mana = 38):
        self.name = name
        self.mana = mana
        self.health = health
        self.speed = speed
        self.strenght = strenght

    def strenght_attack(self):
        crit = False
        default_damage = random.randint(10, 30)
        damage = default_damage + self.strenght
        if default_damage == 30:
            crit = True
        if crit == True:
            damage += random.randint(5, 10)
        player.player_health -=  damage
        return(f"you have been hit by a strenght attack! you took {damage} damage.")
    
    def speed_attack(self):
        crit = False
        default_damage = random.randint(10, 20)
        damage = default_damage + self.speed
        if default_damage == 30:
            crit = True
        if crit == True:
            damage += 40
        player.player_health -= damage
        return(f"you have been hit by a speed attack! you took {damage} damage.")

    def random_attack(self):
         return random.choice([self.speed_attack(), self.strenght_attack()])


player.player_health = 100
print(player.player_health)

goblin = enemy(name = 'goblin')
golem = enemy(name = "golem")
print(goblin.strenght_attack())
print(player.player_health)
🔴 No definitive solution yet