您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

89 行
1.2 KiB

  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 checkDied()
  30. {
  31. return hp <= 0;
  32. }
  33. bool checkAlive()
  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. int getAtt()
  54. {
  55. return att;
  56. }
  57. int defend(int dmg)
  58. {
  59. dmg -= def;
  60. if (dmg > 0)
  61. {
  62. hp -= dmg;
  63. return dmg;
  64. }
  65. else
  66. {
  67. return 0;
  68. }
  69. }
  70. int attack()
  71. {
  72. return att;
  73. }
  74. };
  75. #endif