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.

64 line
984 B

6 年之前
6 年之前
6 年之前
6 年之前
6 年之前
  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. int defend(int dmg)
  38. {
  39. dmg -= def;
  40. if (dmg > 0)
  41. {
  42. hp -= dmg;
  43. return dmg;
  44. }
  45. else
  46. {
  47. return 0;
  48. }
  49. }
  50. int attack()
  51. {
  52. return att;
  53. }
  54. };
  55. #endif