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.
 
 
 
 

147 rader
2.2 KiB

#include "Character.hpp"
#include <cstring>
Character::Character(char *n, int l, int e, int h, int m, int a, int d)
{
strcpy(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;
}
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());
}
void Character::rest()
{
this->curHP = this->maxHP;
this->curMP = this->maxMP;
}
void Character::suicide()
{
this->curHP = 0;
}