Having been here: Python class inherits object, and here What is a metaclass in Python? I'm still unsure of how to get my code working. I'll be honest those explanations were a bit complicated for me. (BTW This is all in Python 3.4).
I'm trying to make Objects for my game in the form of creatures. Example: I want an Object called Dragon, but I want Dragon to inherit the class Entity, and the class Monster.
Here's what I've got:
class Entity:
id = 0
xLocation= 0
yLocation = 0
name = ''
description = ''
def __init__(self, id, xLocation, yLocation, name, description):
self.xLocation = xLocation
self.yLocation = yLocation
self.id = id
self.name = name
self.description = description
class Monster:
life = 0
pierce = 0
slash = 0
blunt = 0
pierceReduction = 0
slashReduction = 0
bluntReduction = 0
defenseBonus = 0
score = 0
def __init__(self, pierceReduction, bluntReduction, slashReduction, price, name, score):
self.pierceReduction = pierceReduction
self.bluntReduction = bluntReduction
self.slashReduction = slashReduction
self.price = price
self.name = name
self.score = score
class Structure:
pass
Monster = Entity
Dragon = Monster
I don't know how I can give Dragon all of the values of both an entity and a Monster? Obviously setting Dragon directly to monster doesn't work.
*****I've now tried this*****:
class Structure: pass
class Dragon(Entity, Monster): pass
Dragon(10, 10, 10, 1000, 'Dragon', 1000)
The Dragon is saying it doesn't have all the parameters of both classes though?