i'm doing a rpg for fun but this one function is giving me problems. it compiles without problems, but when i test it, the hp stats done change. this is the code for the function.
void attack(dragon *d1, dragon *d2)
{
if(d1->getdef() < d2->getatk())
{
d1->changehp(- ( d2->getatk() - d1->getdef() ) );
}else if(d2->getdef() < d1->getatk())
{
d2->changehp(- (d1->getatk() - d2->getdef() ) );
}
if(d1->gethp() == 0)
d1->setout(true); /* set to unconscious */
}
and this is the code for the dragon class
class dragon {
private:
string name;
int atk, def, acc;
int type, lvl, hp, hpmax, exp, expmax;
int out;
public:
dragon(string str = "wild dragon", int level = 5);
string getname(){return name;};
int gethp(){ return hp;};
int gethpmax(){ return hpmax;};
int getexpmax(){ return expmax;};
int getatk(){return atk;};
int getdef(){return def;};
int getexp(){return exp;};
int getacc(){return acc;};
int getout(){return out;};
void changehp(int s);
void setname(string str) { name = str; };
void sethpmax(){hpmax = lvlhp[lvl - 1];};
void setexpmax(){expmax = lvlexp[lvl - 1];};
void setatk();
void setdef();
int getlvl(){return lvl;};
void setout(int s){ out = s;};
void setacc(){acc += 5;};
void setlvl(int level){ lvl = level; };
};
i would appreciate any help you could give me.