#Here is the code I currently have:
class Character(object):
def __init__(self, currentHealth, maxHealth, damage, defence, agility):
self.currentHealth = currentHealth
self.maxHealth = maxHealth
self.damage = damage
self.defence = defence
self.agility = agility
class Enemy(Character):
def __init__(self, drop):
Character.__init__(self, currentHealth, maxHealth, damage, defence, agility)
self.drop = drop
def checkHealth(self):
print("The enemies health is: " + str(self.currentHealth))
def inspectStats(self):
print("The enemies health is: " + str(self.currentHealth))
print("The enemies attack is: " + str(self.damage))
print("The enemies defence is: " + str(self.defence))
print("The enemies evasiveness is: " + str(self.agility))
class Player(Character):
def __init__(self, currentHealth, maxHealth, damage, defence, agility, gold):
self.currentHealth = currentHealth
self.maxHealth = maxHealth
self.damage = damage
self.defence = defence
self.agility = agility
self.gold = gold
def checkHealth(self):
print("Your current health is: " + str(self.currentHealth))
def inspectStats(self):
print("Your current health is: " + str(self.currentHealth))
print("Your max health is: " + str(self.maxHealth))
print("Your attack is: " + str(self.damage))
print("Your defence is: " + str(self.defence))
print("Your agility is: " + str(self.agility))
print("Your gold is: " + str(self.gold))
bob = Player(15, 15, 5, 6, 7, 70)
spider = Enemy(10, 10, 2, 1, 5, 'silk')
spider.inspectStats()
I haven't been able to get this code working, I have searched online and have found mild success with this website: http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/ It appears, however, that the code still isn't working. It would be greatly appreciated if someone could tell me how I am supposed to do inheritance. (I know that there is going to be a subclass of enemy so it would be helpful if that was taken into consideration).