Code: Alles auswählen
class Attack(object):
# ...
def cooldown(self):
self.cooldown_counter -= self.cooldown
def is_usable(self):
return self.cooldown_counter <= self.cooldown
# ...
class Character(object):
# ...
def cooldown(self):
for attack in self.attacks:
attack.cooldown()
def get_usable_attacks(self):
return [attack for attack in self.attacks if attack.is_usable()]
def get_random_attack(self):
return random.choice(self.get_usable_attacks())
# ...
class Game(object):
# ...
def battle(self, opponent):
# ...
self.player.cooldown()
# ...
attack = opponent.get_random_attack()
# ...
# ...