No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

146 líneas
2.2 KiB

hace 5 años
  1. #include "Character.hpp"
  2. #include <cstring>
  3. Character::Character(char *n, int l, int e, int h, int m, int a, int d)
  4. {
  5. strcpy(this->name, n);
  6. this->level = l;
  7. this->experience = e;
  8. this->maxHP = h;
  9. this->curHP = maxHP;
  10. this->maxMP = m;
  11. this->curMP = maxMP;
  12. this->atk = a;
  13. this->def = d;
  14. }
  15. char *Character::getName()
  16. {
  17. return this->name;
  18. }
  19. int Character::getLevel()
  20. {
  21. return this->level;
  22. }
  23. int Character::getExperience()
  24. {
  25. return this->experience;
  26. }
  27. int Character::getMaxHP()
  28. {
  29. return this->maxHP;
  30. }
  31. int Character::getCurHP()
  32. {
  33. return this->curHP;
  34. }
  35. int Character::getMaxMP()
  36. {
  37. return this->maxMP;
  38. }
  39. int Character::getCurMP()
  40. {
  41. return this->curMP;
  42. }
  43. int Character::getAtk()
  44. {
  45. return this->atk;
  46. }
  47. int Character::getDef()
  48. {
  49. return this->def;
  50. }
  51. void Character::levelUp()
  52. {
  53. if ((this->level <= maxLevel) && this->readytoLevelUp())
  54. {
  55. this->level++;
  56. this->maxHP += 10;
  57. this->maxMP += 5;
  58. }
  59. this->curHP = this->maxHP;
  60. this->curMP = this->maxMP;
  61. }
  62. void Character::restoreHP(int n)
  63. {
  64. this->curHP += n;
  65. if (this->curHP > this->maxHP)
  66. {
  67. this->curHP = this->maxHP;
  68. }
  69. }
  70. void Character::restoreMP(int n)
  71. {
  72. this->curMP += n;
  73. if (this->curMP > this->maxMP)
  74. {
  75. this->curMP = this->maxMP;
  76. }
  77. }
  78. void Character::reduceHP(int n)
  79. {
  80. this->curHP -= n;
  81. }
  82. void Character::reduceMP(int n)
  83. {
  84. this->curMP -= n;
  85. }
  86. bool Character::isAlive()
  87. {
  88. return this->curHP > 0;
  89. }
  90. int Character::toNextLevel()
  91. {
  92. return (this->level <= maxLevel) ? ((this->level + 1) * (this->level + 1)) - this->getExperience() : 999999;
  93. }
  94. bool Character::readytoLevelUp()
  95. {
  96. return (this->toNextLevel() <= 0);
  97. }
  98. void Character::increaseExperience(int n)
  99. {
  100. this->experience += n;
  101. if (this->experience > maxEperience)
  102. {
  103. this->experience = maxEperience;
  104. }
  105. }
  106. bool Character::canCastSpell(Spell *s)
  107. {
  108. return this->curMP >= s->getCost();
  109. }
  110. void Character::castSpell(Spell *s, Character *t)
  111. {
  112. this->reduceMP(s->getCost());
  113. t->reduceHP(s->getAmount());
  114. }
  115. void Character::rest()
  116. {
  117. this->curHP = this->maxHP;
  118. this->curMP = this->maxMP;
  119. }
  120. void Character::suicide()
  121. {
  122. this->curHP = 0;
  123. }