Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstdlib>
- using namespace std;
- class Entity
- {
- private:
- string name;
- int health;
- int maxHealth;
- int damage;
- public:
- Entity(string entityName)
- {
- name = entityName;
- maxHealth = 10;
- health = maxHealth;
- damage = 2;
- }
- string get_name()
- {
- return name;
- }
- int get_health()
- {
- return health;
- }
- int get_max_health()
- {
- return maxHealth;
- }
- int get_damage()
- {
- return damage;
- }
- void lower_health(int value)
- {
- health -= value;
- if (health < 0)
- {
- health = 0;
- }
- }
- void add_health(int value)
- {
- health += value;
- if (health > maxHealth)
- {
- health = maxHealth;
- }
- }
- };
- class Player : public Entity
- {
- private:
- int metal;
- int oxygen;
- public:
- Player(string playerName) : Entity(playerName)
- {
- metal = 0;
- oxygen = 100;
- }
- Player() : Entity("John")
- {
- }
- int get_metal()
- {
- return metal;
- }
- int get_oxygen()
- {
- return oxygen;
- }
- void display_player_info()
- {
- cout << "Stan gracza" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "Życie: " << get_health() << "/" << get_max_health() << endl;
- cout << "Atak: " << get_damage() << endl;
- cout << "Tlen: " << oxygen << "%" << endl;
- cout << "Metal: " << metal << "/50" << endl;
- }
- void rest()
- {
- cout << get_name() << " odpoczywa. Zużycie 2% tlenu." << endl << endl;
- lower_oxygen(2);
- add_health(5);
- display_player_info();
- }
- void lower_oxygen(int value)
- {
- oxygen -= value;
- }
- void add_oxygen(int value)
- {
- if(oxygen + value > 100)
- {
- oxygen = 100;
- }
- else
- {
- oxygen += value;
- }
- }
- void add_metal(int value)
- {
- metal += value;
- }
- };
Add Comment
Please, Sign In to add comment