You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #ifndef _2EASY4ME_CHARACTER_H_
  2. #define _2EASY4ME_CHARACTER_H_
  3. #include <cstring>
  4. class Character
  5. {
  6. protected:
  7. char name[16];
  8. int maxHp;
  9. int hp;
  10. int att;
  11. int def;
  12. public:
  13. Character(char *name)
  14. {
  15. strncpy(this->name, name, sizeof(this->name));
  16. this->maxHp = 100;
  17. this->hp = 100;
  18. this->att = 10;
  19. this->def = 5;
  20. }
  21. Character(char *name, int hp, int att, int def)
  22. {
  23. strncpy(this->name, name, sizeof(this->name));
  24. this->maxHp = hp;
  25. this->hp = hp;
  26. this->att = att;
  27. this->def = def;
  28. }
  29. bool isDead()
  30. {
  31. return hp <= 0;
  32. }
  33. bool isAlive()
  34. {
  35. return hp > 0;
  36. }
  37. bool restoreHP()
  38. {
  39. this->hp = this->maxHp;
  40. }
  41. int checkHP()
  42. {
  43. return hp;
  44. }
  45. int getMaxHP()
  46. {
  47. return maxHp;
  48. }
  49. int getDef()
  50. {
  51. return def;
  52. }
  53. char *getName()
  54. {
  55. return name;
  56. }
  57. int getAtt()
  58. {
  59. return att;
  60. }
  61. int defend(int dmg)
  62. {
  63. dmg -= def;
  64. if (dmg > 0)
  65. {
  66. hp -= dmg;
  67. return dmg;
  68. }
  69. else
  70. {
  71. return 0;
  72. }
  73. }
  74. int attack()
  75. {
  76. return att;
  77. }
  78. };
  79. #endif