Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

135 wiersze
2.1 KiB

#include "Character.hpp"
Character::Character(const char *n, int l, int e, int h, int m, int a, int d)
{
this->name = n;
this->level = l;
this->experience = e;
this->maxHP = h;
this->curHP = maxHP;
this->maxMP = m;
this->curMP = maxMP;
this->atk = a;
this->def = d;
}
const char *Character::getName()
{
return this->name;
}
int Character::getLevel()
{
return this->level;
}
int Character::getExperience()
{
return this->experience;
}
int Character::getMaxHP()
{
return this->maxHP;
}
int Character::getCurHP()
{
return this->curHP;
}
int Character::getMaxMP()
{
return this->maxMP;
}
int Character::getCurMP()
{
return this->curMP;
}
int Character::getAtk()
{
return this->atk;
}
int Character::getDef()
{
return this->def;
}
void Character::levelUp()
{
if ((this->level <= maxLevel) && this->readytoLevelUp())
{
this->level++;
this->maxHP += 10;
this->maxMP += 5;
}
this->curHP = this->maxHP;
this->curMP = this->maxMP;
}
void Character::restoreHP(int n)
{
this->curHP += n;
if (this->curHP > this->maxHP)
{
this->curHP = this->maxHP;
}
}
void Character::restoreMP(int n)
{
this->curMP += n;
if (this->curMP > this->maxMP)
{
this->curMP = this->maxMP;
}
}
void Character::reduceHP(int n)
{
this->curHP -= n;
}
void Character::reduceMP(int n)
{
this->curMP -= n;
}
bool Character::isAlive()
{
return this->curHP > 0;
}
int Character::toNextLevel()
{
return (this->level <= maxLevel) ? ((this->level + 1) * (this->level + 1)) - this->getExperience() : 999999;
}
bool Character::readytoLevelUp()
{
return (this->toNextLevel() <= 0);
}
void Character::increaseExperience(int n)
{
this->experience += n;
if (this->experience > maxEperience)
{
this->experience = maxEperience;
}
}
bool Character::canCastSpell(Spell *s)
{
return this->curMP >= s->getCost();
}
void Character::castSpell(Spell *s, Character *t)
{
this->reduceMP(s->getCost());
t->reduceHP(s->getAmount());
}