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.

152 líneas
2.5 KiB

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