Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

95 rader
1.3 KiB

#ifndef _2EASY4ME_CHARACTER_H_
#define _2EASY4ME_CHARACTER_H_
#include <cstring>
class Character
{
protected:
char name[16];
int maxHp;
int hp;
int att;
int def;
public:
Character(char *name)
{
strncpy(this->name, name, sizeof(this->name));
this->maxHp = 100;
this->hp = 100;
this->att = 10;
this->def = 5;
}
Character(char *name, int hp, int att, int def)
{
strncpy(this->name, name, sizeof(this->name));
this->maxHp = hp;
this->hp = hp;
this->att = att;
this->def = def;
}
bool isDead()
{
return hp <= 0;
}
bool isAlive()
{
return hp > 0;
}
bool restoreHP()
{
this->hp = this->maxHp;
}
int checkHP()
{
return hp;
}
int getMaxHP()
{
return maxHp;
}
int getDef()
{
return def;
}
char *getName()
{
return name;
}
int getAtt()
{
return att;
}
int defend(int dmg)
{
dmg -= def;
if (dmg > 0)
{
hp -= dmg;
return dmg;
}
else
{
return 0;
}
}
int attack()
{
return att;
}
};
#endif