25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

152 satır
2.5 KiB

#include "Character.hpp"
std::vector<const char *> Character::playerNames = {
"Abby",
"John",
"Adam",
"Johny",
"Christo",
"Greg",
};
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;
}
std::vector<Character *> Character::Enemies = {
new Character("Red Mage", 1, 1, 10, 5, 1, 1),
new Character("Green Mage", 2, 3, 20, 10, 1, 1),
new Character("Blue Mage", 3, 7, 40, 25, 1, 1),
new Character("White Mage", 4, 11, 80, 40, 1, 1),
new Character("Black Mage", 5, 16, 160, 80, 1, 1),
};
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());
}