I believe I'm the one who told you to ask yourself the question: "Is class A a class B, or does class A have a class B?", so I feel like I have to answer this question.
I'm not 100% sure of what your level actually does, but I'm assuming it's one similar to the one used in Pokemon, World of Warcraft, League of Legends, and thousands of other games.
If so, you've already gone wrong with your Level
-class, it shouldn't be like that.
You're right on one thing for sure;
"Player certainly is not a level"
As others have already mentioned, you should just go with has-a relationship.
Player does have level, we both know that.
However, you're telling me player doesn't have an attribute of type Level
, but rather an integer level
-attribute to hold the numeric value of your Level
-class.
This should already ring some bells, but here's a tip: It's the same as having a Name
-class that has a string
-type attribute called name
inside it.
So the answer is:
Name
class should already be a string itself, it should inherit from string
, instead of having a string
attribute inside it to hold its value.
The same applies for your Level
, it's already an integer itself so inherit it from int
, then add exp
and its methods.
Now you can use player.level
to return the integer value of player's level.
And to get the exp
, you "have to" use player.level.exp
.
I quoted the "have to", since even though it might sound weird, exp
IS an attribute of level's.
It's basically the same as a decimal point for a number, makes sense?
Also, calling something like player.level.increase()
makes much more sense now.
Although, it's already an integer value, why not just do player.level += 1
?
And if you need some advanced stuff inside the addition, you could just override the Level.__add__(self, value)
method.
I can't think of a single reason why wouldn't you need this though? (not now that you've already made required_exp
a property)