Advertisement
Cassimus

Rpg1

Mar 15th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. /**Klasa dowolnej postaci*/
  6. class Character // Entity
  7. {
  8. private:
  9. string name;
  10. int health;
  11. int maxHealth;
  12. int damage;
  13.  
  14. public:
  15. Character(string characterName)
  16. {
  17. name = characterName;
  18. maxHealth = 10;
  19. health = maxHealth;
  20. damage = 2;
  21. }
  22.  
  23. string get_name() const
  24. {
  25. return name;
  26. }
  27.  
  28. int get_health() const
  29. {
  30. return health;
  31. }
  32.  
  33. int get_max_health() const
  34. {
  35. return maxHealth;
  36. }
  37.  
  38. int get_damage() const
  39. {
  40. return damage;
  41. }
  42. /**
  43. * Dodaje zdrowia postaci
  44. * @param value ilość zdrowia do dodania
  45. * @return nic nie zwraca
  46. */
  47. void add_health(int value)
  48. {
  49. health += value;
  50.  
  51. if (health > maxHealth)
  52. health = maxHealth;
  53. }
  54.  
  55. void lower_health(int value)
  56. {
  57. health -= value;
  58. if (health < 0)
  59. health = 0;
  60. }
  61. };
  62.  
  63. class Player : public Character
  64. {
  65. private:
  66. int metal;
  67. int oxygen;
  68.  
  69. public:
  70. Player(string playerName) : Character(playerName)
  71. {
  72. metal = 0;
  73. oxygen = 100;
  74. }
  75.  
  76. Player() : Player("John Doe")
  77. {
  78. }
  79.  
  80. int get_metal() const
  81. {
  82. return metal;
  83. }
  84.  
  85. int get_oxygen() const
  86. {
  87. return oxygen;
  88. }
  89.  
  90. void lower_oxygen(int value)
  91. {
  92. oxygen -= value;
  93. if (oxygen < 0)
  94. oxygen = 0;
  95. }
  96.  
  97. void add_oxygen(int value)
  98. {
  99. oxygen += value;
  100. if (oxygen > 100)
  101. oxygen = 100;
  102. }
  103.  
  104. void add_metal(int value)
  105. {
  106. metal += value;
  107. }
  108.  
  109. void rest()
  110. {
  111. cout << this->get_name() << " odpoczywa. Zużywa 2% tlenu." << endl
  112. << endl;
  113. this->lower_oxygen(2);
  114. this->add_health(5);
  115.  
  116. display_player_info();
  117. }
  118.  
  119. void display_player_info()
  120. {
  121. cout << "Stan gracza" << endl;
  122. cout << "-----------------------------------------------------------------" << endl;
  123. cout << "Życie: " << this->get_health() << "/" << this->get_max_health() << endl;
  124. cout << "Atak: " << this->get_damage() << endl;
  125. cout << "Tlen: " << this->get_oxygen() << endl;
  126. cout << "Metal: " << this->get_metal() << endl;
  127. }
  128. };
  129.  
  130. class SpaceRescue
  131. {
  132. private:
  133. /* data */
  134. public:
  135. SpaceRescue(/* args */);
  136.  
  137. };
  138.  
  139.  
  140.  
  141.  
  142. using Entity = Character;
  143.  
  144. int main(int argc, char const *argv[])
  145. {
  146. Character character("Steven");
  147. Player player("Casimus");
  148. player.lower_health(5);
  149. player.lower_oxygen(7);
  150. player.display_player_info();
  151. player.rest();
  152.  
  153.  
  154. return 0;
  155. }
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement