I have a class of Player with a number of attributes to measure their overall state. I have a second class of Character (Class Type) that sets up some unique configurations for my players depending on their instance of character. Where I am having trouble, is calling a single generic function at the player level that measures the unique milestone goals for each character. i.e Check each player to see if they have reached their unique Milestone 1. I originally tried to do this with a series of conditional functions under the initialization, but this proved to be ill-advised in a class, so I moved it out to its own single function. Since doing this, it obviously fails because the attributes the function are checking for are in the parent class (Player) and not the class where the function is defined (Character).
class Player:
def __init__(self, player_num, name):
self.character = Character(name)
self.player_num = player_num
self.name = name
self.power = 0
self.position = 1
self.attributeLimit = 4
self.attributes = []
self.attachments = []
self.collection = []
self.visited = []
self.setCharacterValues()
self.ms1 = self.character.Milestone1
def setCharacterValues()
#Loads Character instance data into the Player instance.
class Character:
def __init__(self, name):
self.attributes = []
self.attachments = []
self.collection = []
self.visited = []
self.name = name
if name == 'char x':
self.attributes = [1,2,3]
#etc.
#etc.
def Milestone1(self):
if self.name == 'char x':
if self.power >= 20:
return True
else:
return False
if self.name == 'char y':
if self.position >= 5:
return True
else:
return False
#etc
for i in players:
if i.ms1():
print('Passed')
Now the only solution that I can think of, is to simply move the function from the Character class to the Player class. But this seems to be counter intuitive to me, because this function is measuring each unique characters ability to reach the milestone. It feels appropriate to leave it under Character, and I'm just missing an obvious step somewhere. Can anyone lend some assistance?