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.

61 lines
916 B

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 hp;
  9. int att;
  10. int def;
  11. public:
  12. Character(char *name)
  13. {
  14. strncpy(this->name, name, sizeof(this->name));
  15. this->hp = 100;
  16. this->att = 10;
  17. this->def = 5;
  18. }
  19. Character(char *name, int hp, int att, int def)
  20. {
  21. strncpy(this->name, name, sizeof(this->name));
  22. this->hp = hp;
  23. this->att = att;
  24. this->def = def;
  25. }
  26. bool checkDied()
  27. {
  28. return hp <= 0;
  29. }
  30. bool checkAlive()
  31. {
  32. return hp > 0;
  33. }
  34. int defend(int dmg)
  35. {
  36. dmg -= def;
  37. if (dmg > 0)
  38. {
  39. hp -= dmg;
  40. return dmg;
  41. }
  42. else
  43. {
  44. return 0;
  45. }
  46. }
  47. int attack()
  48. {
  49. return att;
  50. }
  51. };
  52. #endif