You can override an inherited method in a class by simply re-defining it in the subclass.
#[combat.py]:
import random
class Combat:
dodge_limit = 6
attack_limit = 6
def dodge(self):
roll = random.randint(1, self.dodge_limit)
return roll > 4
def attack(self):
roll = random.randint(1, self.attack_limit)
return roll > 4
#[character.py]: import random from combat import Combat class Character(Combat): attack_limit = 10 experience = 0 hit_points = 10 def attack(self): roll = random.randint(1, self.attack_limit) if self.weapon = 'sword': roll += 1 elif self.weapon == 'axe': roll += 2 return roll > 4 def get_weapon(self): weapon_choice = input("Weapon ([S]word, [A]xe, [B]ow): ").lower() if weapon_choice in 'sab': if weapon_choice == 's': return 'sword' elif weapon_choice == 'a': return 'axe' else: return 'bow' else: return self.get_weapon() def __init__(self, **kwargs): self.name = input("Name: ") self.weapon = self.get_weapon() ...
#[Monster.py]:
...