My code is below. For now I'm focusing on the lines where health (and
armor) are increased in each character class. Let's say I decided to
change the amount of increase in the future. As it is now, I'd have to
go to each character class and change the number so that each is still
in a good relation to the other (right now: 3, 2, 1; later: perhaps 4,
3, 2, 1, if I added a new class -- i.e., change Fighter from 3 to 4,
Thief from 2 to 3, in other words increase them all by 1). So instead of
changing each one, is there a simple, clean way of just changing a
single number so that this change is reflected in all classes? Hope that
makes sense.
class Character(objec t):
def __init__(self, name, strength, dexterity, intelligence):
self.name = name
self.health = 10
self.armor = self.attack = self.defense = self.magic_atta ck = \
self.magic_defe nse = 0
self.strength = strength
self.dexterity = dexterity
self.intelligen ce = intelligence
self.adjust_att ributes()
def adjust_attribut es(self):
pass
class Fighter(Charact er):
def adjust_attribut es(self):
self.health += 3
self.armor += 3
self.attack += 2
self.defense += 2
self.strength += 1
class Thief(Character ):
def adjust_attribut es(self):
self.health += 2
self.armor += 2
self.attack += 1
self.defense += 1
self.magic_defe nse += 1
self.dexterity += 1
class Mage(Character) :
def adjust_attribut es(self):
self.health += 1
self.armor += 1
self.magic_atta ck += 2
self.magic_defe nse += 2
self.intelligen ce += 1
armor) are increased in each character class. Let's say I decided to
change the amount of increase in the future. As it is now, I'd have to
go to each character class and change the number so that each is still
in a good relation to the other (right now: 3, 2, 1; later: perhaps 4,
3, 2, 1, if I added a new class -- i.e., change Fighter from 3 to 4,
Thief from 2 to 3, in other words increase them all by 1). So instead of
changing each one, is there a simple, clean way of just changing a
single number so that this change is reflected in all classes? Hope that
makes sense.
class Character(objec t):
def __init__(self, name, strength, dexterity, intelligence):
self.name = name
self.health = 10
self.armor = self.attack = self.defense = self.magic_atta ck = \
self.magic_defe nse = 0
self.strength = strength
self.dexterity = dexterity
self.intelligen ce = intelligence
self.adjust_att ributes()
def adjust_attribut es(self):
pass
class Fighter(Charact er):
def adjust_attribut es(self):
self.health += 3
self.armor += 3
self.attack += 2
self.defense += 2
self.strength += 1
class Thief(Character ):
def adjust_attribut es(self):
self.health += 2
self.armor += 2
self.attack += 1
self.defense += 1
self.magic_defe nse += 1
self.dexterity += 1
class Mage(Character) :
def adjust_attribut es(self):
self.health += 1
self.armor += 1
self.magic_atta ck += 2
self.magic_defe nse += 2
self.intelligen ce += 1
Comment