Imagine that you did have a class called Peon which had the following attributes and methods:
self.hp = 100
def takeDamage(self, dmg):
self.hp = self.hp - dmg
As you can see, peons have limited abilities. They only have default health point of 100 and can't attack but can only takeDamage.
Imagine that you wanted to create a new class called Warrior. You want warrior to have everything that a Peon has. You also want the warrior to do everything that a Peon can do. In addition, however, you want to set it up such that
- when a warrior is created, you want the default hp to be 200!
- you want the warrior to have a default 'armor' of 70, which means 70% of the damage will be reduced.
- you want to add a new method called attack(), which returns a random integer between 10 to 20.
- you want the warrior to override the takeDamage(dmg) method. This time, its hp would only go down by 30% of dmg (as its armor would have absorbed 70% of dmg).
Finish implementing class Warrior using inheritance.