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.

56 regels
858 B

6 jaren geleden
  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. int defend(int dmg)
  31. {
  32. dmg -= def;
  33. if (dmg > 0)
  34. {
  35. hp -= dmg;
  36. return dmg;
  37. }
  38. else
  39. {
  40. return 0;
  41. }
  42. }
  43. int attack()
  44. {
  45. return att;
  46. }
  47. };
  48. #endif