jeudi 14 mai 2020

Python, import random not showing a new random number when its called again

I need a random number each time self.damage or self.dodge is called. But once its called, it doesn't change.

class Character:
is_dead = 0

def __init__(self, race, health, damage, dodge):
    self.race = race
    self.health = health
    self.damage = random.randint(damage[0], damage[1])
    self.dodge = random.randint(0, round(100 / dodge))

def hit(self, attack):
    if self.dodge == 0:
        self.health = self.health
    elif attack > 100:
        self.health = 0
    elif attack < 0:
        self.health = 100
    elif self.health - attack <= 0:
        self.health = 0
    else:
        self.health = self.health - attack
    return self.health

Here is where i call it.

ork = Character("Ork", 150, (50, 80), 1)
human = Character("Human", 100, (40, 60), 33)

ork.hit(human.damage)

It's called in a loop each time, the whole code is too long to show.




Aucun commentaire:

Enregistrer un commentaire