Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- /**Klasa dowolnej postaci*/
- class Character // Entity
- {
- private:
- string name;
- int health;
- int maxHealth;
- int damage;
- public:
- Character(string characterName)
- {
- name = characterName;
- maxHealth = 10;
- health = maxHealth;
- damage = 2;
- }
- string get_name() const
- {
- return name;
- }
- int get_health() const
- {
- return health;
- }
- int get_max_health() const
- {
- return maxHealth;
- }
- int get_damage() const
- {
- return damage;
- }
- /**
- * Dodaje zdrowia postaci
- * @param value ilość zdrowia do dodania
- * @return nic nie zwraca
- */
- void add_health(int value)
- {
- health += value;
- if (health > maxHealth)
- health = maxHealth;
- }
- void lower_health(int value)
- {
- health -= value;
- if (health < 0)
- health = 0;
- }
- };
- class Player : public Character
- {
- private:
- int metal;
- int oxygen;
- public:
- Player(string playerName) : Character(playerName)
- {
- metal = 0;
- oxygen = 100;
- }
- Player() : Player("John Doe")
- {
- }
- int get_metal() const
- {
- return metal;
- }
- int get_oxygen() const
- {
- return oxygen;
- }
- void lower_oxygen(int value)
- {
- oxygen -= value;
- if (oxygen < 0)
- oxygen = 0;
- }
- void add_oxygen(int value)
- {
- oxygen += value;
- if (oxygen > 100)
- oxygen = 100;
- }
- void add_metal(int value)
- {
- metal += value;
- }
- void rest()
- {
- cout << this->get_name() << " odpoczywa. Zużywa 2% tlenu." << endl
- << endl;
- this->lower_oxygen(2);
- this->add_health(5);
- display_player_info();
- }
- void display_player_info()
- {
- cout << "Stan gracza" << endl;
- cout << "-----------------------------------------------------------------" << endl;
- cout << "Życie: " << this->get_health() << "/" << this->get_max_health() << endl;
- cout << "Atak: " << this->get_damage() << endl;
- cout << "Tlen: " << this->get_oxygen() << endl;
- cout << "Metal: " << this->get_metal() << endl;
- }
- };
- class SpaceRescue
- {
- private:
- /* data */
- public:
- SpaceRescue(/* args */);
- };
- using Entity = Character;
- int main(int argc, char const *argv[])
- {
- Character character("Steven");
- Player player("Casimus");
- player.lower_health(5);
- player.lower_oxygen(7);
- player.display_player_info();
- player.rest();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement