Also remember that when you do
Code: Select all
reference_name = Element(arguments)
you are instantiating an object with that reference, so anything later in the code that uses that reference is just pointing at that single one instance of the object.
Think of it like making some word docs in one global folder, calling one of them fire.doc (fire.doc = new WordDoc(contents) ) means you cannot have a second fire.doc unless you use a different pointer/name such as fire2.doc. Even if the contents of the .docs are the same, their filenames/references have to be different... so, if something is weak to fire.doc it does not automatically become weak to fire2.doc.
Hope that kind of made sense.
Also, try to think of how and when you will need the objects, it should help you design the class nicely.... e.g. (if you wanted a name and type)
enemy1 = Element('Bob the Firey Enemy', 'fire', ... some data)
friend1 = Element('Drippy the umm drippy watery friend', 'water')
On an aside, you could extend the classes using a base class and children inheriting from that...
Code: Select all
class Element(object):
def __init__(self, name):
self.name = name
self.type = None
self.resist = []
self.weak = []
# this method also appears in any child class based on Element
# Most methods (functions within classes) will appear in this parent class
def test_resist(self, attacker_type):
return attacker_type in self.resist
class FireElement(Element): # Class based on Element
def __init__(self, name):
# This line basically just calls the parent __init__ as though it existed in this object
# It would set self.name then set up empty .type, .resist and .weak variables
super(FireElement, self).__init__(name)
# We can then amend them after we call it to make objects of this class slightly different
self.type = 'fire'
self.resist = ['fire', 'lava']
self.weak = ['water', 'ice']
# then define IceElement, WaterElement... etc
enemy1 = FireElement('Bob the pest')
resisted = enemy1.test_resist('lava')
Typed on the fly, ergo untested.
Hopefully it gives some ideas for possible options though.