thank you for reaching out for help about this.
There are actually quite a lot of tutorials on classes and how they work. I'd suggest finding a blog, book, or video and just work through it.
However for your particular issue I'd suggest setting up your minion as it's own class. Then setting up your boss with a spawn method that creates minions.
You'll need the super constructor for this to work.
The idea behind this is that your class "hierarchy" will look like this:
Object
|
Character
|
Boss
What this shows us is that all of your classes will be children of Object
. Boss
is a child of Character
. It is common to hear this relationship described as a "is a". i.e. Boss is a Character.
Moving forward.
Let's imagine your character
class looks like this:
class Character(Object):
def __init__(self, name="Placeholder",
level=1, hp=10, attack=10,
defense=10, experience=0):
self.name = name
self.level = level
self.hp = hp
self.attack = attack
self.defense = defense
self.experience = experience
Spawning a minion from you boss is rather simple. Try constructing a new character with the relevant stats. This might look something like the following:
class Boss(Character):
'''
Defines the boss class.
Which by default has the following values:
Name: "Boss"
level: 100
hp: 10000
attack: 1000
defense: 1000
experience: 10000
'''
def __init__(self, name="Boss", level=100,
hp=10000, attack=1000, defense=1000,
defense=1000, experience=10000):
super(Boss, self).__init__(
name=name, level=level,
hp=hp, attack=attack,
defense=defense, experience=experience
)
def spawn(self):
'''
Spawns a single minion
'''
return Character(name="Minion", level=self.level,
hp=round(self.hp / 4),
attack=round(self.attack / 4),
defense=0, experience=0)
There are tons of other ways to accomplish this using other paradigms, but this is a good starting point for OOP. If you'd like a little help with types and even spawning different kinds of minions I'd suggest researching enums in python.
EDIT: Example including Minion
subclass
This would change your inheritance tree like so:
Object
|
Character
| |
Boss Minion
Which, again. Means both your Boss
and Minion
are children of Character
and thus by extension are children of Object
.
You can describe this as: "Boss and Minion are Characters".
Edited code below:
class Character(Object):
def __init__(self, name="Placeholder",
level=1, hp=10, attack=10,
defense=10, experience=0):
self.name = name
self.level = level
self.hp = hp
self.attack = attack
self.defense = defense
self.experience = experience
class Minion(Character):
'''
TODO: define any special attributes,
abilities, etc of the minion
'''
pass
class Boss(Character):
'''
Defines the boss class.
Which by default has the following values:
Name: "Boss"
level: 100
hp: 10000
attack: 1000
defense: 1000
experience: 10000
'''
def __init__(self, name="Boss", level=100,
hp=10000, attack=1000, defense=1000,
defense=1000, experience=10000):
super(Boss, self).__init__(
name=name, level=level,
hp=hp, attack=attack,
defense=defense, experience=experience
)
def spawn(self):
'''
Spawns a single minion
'''
return Minion(name="Minion", level=self.level,
hp=round(self.hp / 4),
attack=round(self.attack / 4),
defense=0, experience=0)