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;
- }
- };
- class Game
- {
- private:
- Player player;
- public:
- Game(string playerName)
- {
- player = Player(playerName);
- cout << player.get_name() << endl;
- }
- void start_game()
- {
- cout << "------------------------------------------------" << endl;
- cout << "Rozbiłeś się na księżycu!" << endl;
- cout << "Twoim zadaniem jest przetrwanie i zdobycie wystarczająco dużo surowców by zbudować statek do domu." << endl;
- cout << "Uważaj na zapasy swojego tlenu, bez niego nie możesz kontynuować gry." << endl ;
- cout << "Powodzenia " << player.get_name() << "!" << endl << endl;
- player.display_player_info();
- bool gameRunning = true;
- int playerChoice;
- while(gameRunning)
- {
- print_main_menu();
- cout << "Wpisz numer: ";
- cin >> playerChoice;
- switch (playerChoice)
- {
- case 1:
- player.display_player_info();
- break;
- case 2:
- player.rest();
- break;
- case 3:
- search_resources();
- if(player.get_health() <= 0)
- {
- cout << "Gracz przegrywa!" << endl;
- cout << "Koniec gry! Spróbuj ponownie!" << endl;
- gameRunning = false;
- }
- break;
- case 4:
- if(player.get_metal() >= 50)
- {
- cout << "Gracz wygrywa!" << endl;
- cout << "Pomyślnie zbudowałeś statek i wydostałeś się z księżyca!" << endl;
- cout << "Dzięki za gre!" << endl;
- }
- else
- {
- cout << "Nie masz wystarczająco dużo metalu by zbudować statek." << endl;
- }
- break;
- case 0:
- cout << "Koniec gry!" << endl;
- gameRunning = false;
- break;
- }
- }
- }
- void print_main_menu()
- {
- cout << endl << "Co chcesz zrobić?" << endl;
- cout << "------------------------------------------------" << endl;
- cout << "[1] Sprawdź swój stan." << endl;
- cout << "[2] Odpocznij." << endl;
- cout << "[3] Szukaj zasobów." << endl;
- if (player.get_metal() >= 50)
- {
- cout << "[4] Zbuduj statek." << endl;
- }
- cout << "[0] Skończ grę." << endl;
- }
- }
Add Comment
Please, Sign In to add comment