Today i moved away from std::unique_ptr and tried to undestand the overloading of operators, at first i didnt really undertand but i think im getting there and i think that this might be the best advice that someone has gave me. Today i had to other things so cut a small piece of time that i had to write an HP class. Tell me what you think about it as a first time trying to understand more advanced things. Before you ask me about the operator += that doesnt heal if you are dead, in many turn based combact games if you are dead you have to revive the member with a special item so i will probably be writing a revive function. Heres the class!(i know that theres a bug with the constructor that if you try to give currentHP a value higher than maxHp it wont hesitate and do it, but after 3 hours of studying math i didnt really care and wanted to try for the first time, in the future i will fix it)
class healthPoints{
private:
int maxHp;
int currentHp;
public:
healthPoints(int mh, int ch) : maxHp(mh), currentHp(ch) {}
void operator-=(int damage){
currentHp -= damage;
if(currentHp<0){
currentHp = 0;
}
}
void operator+=(int heal){
if(currentHp){
currentHp += heal;
if(currentHp>=maxHp){
currentHp = maxHp;
}
}
}
explicit operator bool() const{
return currentHp > 0;
}
};