Advertisement
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 Hero
- {
- public:
- // Atrybuty
- string name;
- int health;
- int strength;
- int intelligence;
- vector<string> equipment;
- // Konstruktor
- Hero(string heroName, int heroHealth, int heroStrength, int heroIntelligence)
- {
- name = heroName;
- health = heroHealth;
- strength = heroStrength;
- intelligence = heroIntelligence;
- }
- // Metody
- void attack()
- {
- // Symulacja ataku
- cout << name << " is attacking with strength " << strength << endl;
- }
- void defend()
- {
- // Symulacja obrony
- cout << name << " is defending with health " << health << endl;
- }
- void gather_resources()
- {
- // Symulacja zbierania surowców
- cout << name << " is gathering resources with intelligence " << intelligence << endl;
- }
- };
- // Klasa dla Przeciwnika (Enemy)
- class Enemy
- {
- public:
- // Atrybuty
- vector<string> types = {"alien", "robot"};
- string type;
- int health;
- int strength;
- // Konstruktor
- Enemy() {
- type = types[rand() % types.size()];
- health = rand() % 25 + 25;
- strength = rand() % 3 + 5;
- }
- // Metody
- void attack() {
- // Symulacja ataku
- cout << type << " is attacking with strength " << strength << endl;
- }
- void defend() {
- // Symulacja obrony
- cout << type << " is defending with health " << health << endl;
- }
- };
- // Klasa dla Surowców (Resources)
- class Resources {
- public:
- // Atrybuty
- int metal;
- int fuel;
- int food;
- // Konstruktor
- Resources(int initialMetal, int initialFuel, int initialFood) {
- metal = initialMetal;
- fuel = initialFuel;
- food = initialFood;
- }
- // Metody
- void gather_metal() {
- // Symulacja zbierania metalu
- cout << "Gathering metal. Current metal: " << ++metal << endl;
- }
- void gather_fuel() {
- // Symulacja zbierania paliwa
- cout << "Gathering fuel. Current fuel: " << ++fuel << endl;
- }
- void gather_food() {
- // Symulacja zbierania jedzenia
- cout << "Gathering food. Current food: " << ++food << endl;
- }
- };
- class Game
- {
- public:
- // Atrybuty
- Hero hero;
- Resources resources;
- // Konstruktor
- Game(Hero gameHero, Resources gameResources) :
- hero(gameHero), resources(gameResources) {}
- // Metody
- void start_game()
- {
- // Rozpoczęcie gry
- cout << "Game has started. Good luck, " << hero.name << "!" << endl;
- bool game;
- while (game)
- {
- cout << "\n**************\n" << endl;
- cout << "What action would you like to take?" << endl;
- cout << "1. Look for resources." << endl;
- cout << "2. Fight an enemy." << endl;
- cout << "3. Attempt to build the spacecraft." << endl;
- cout << "4. Check inventory." << endl;
- cout << "5. Rest and regenerate health." << endl;
- cout << "Enter your choice: ";
- int choice;
- int type;
- cin >> choice;
- cout << "\n**************\n" << endl;
- switch (choice)
- {
- case 1:
- type = rand() % 3;
- switch (type)
- {
- case 0:
- resources.gather_metal();
- break;
- case 1:
- resources.gather_fuel();
- break;
- case 2:
- resources.gather_food();
- break;
- }
- break;
- case 2:
- battle();
- if (hero.health <= 0)
- {
- game = false;
- cout << "You perished stranded on the alien world!" << endl;
- }
- break;
- case 3:
- if (resources.fuel > 5 && resources.metal > 10)
- {
- cout << "You succeed in building an airship! You won!" << endl;
- end_game();
- game = false;
- }
- else
- {
- cout << "You don't have enough resources to build an airship..." << endl;
- }
- break;
- case 4:
- cout << "You check your inventory, you find: " << endl;
- cout << resources.metal << " metal " << endl;
- cout << resources.food << " food " << endl;
- cout << resources.fuel << " fuel " << endl;
- break;
- case 6:
- cout << "You feel well rested." << endl;
- hero.health += 15;
- break;
- default:
- cout << "Invalid choice. Try again." << endl;
- }
- }
- }
- void end_game()
- {
- // Zakończenie gry
- cout << "Game over. Thanks for playing!" << endl;
- }
- void battle()
- {
- Enemy enemy = Enemy();
- cout << "Battle has started!" << endl;
- bool battleOn = true;
- while (battleOn) {
- cout << "\n**************\n" << endl;
- cout << "Your health: " << hero.health << endl;
- cout << "Enemy's health: " << enemy.health << "\n" << endl;
- cout << "What action would you like to take?" << endl;
- cout << "1. Fight!" << endl;
- cout << "2. Run away!" << endl;
- cout << "Enter your choice: ";
- int choice;
- cin >> choice;
- cout << "\n**************\n" << endl;
- switch (choice)
- {
- // Atakowanie
- case 1:
- hero.attack();
- enemy.health -= hero.strength;
- enemy.defend();
- if (enemy.health <= 0)
- {
- battleOn = false;
- cout << "You win the fight!" << endl;
- }
- else
- {
- enemy.attack();
- hero.health -= enemy.strength;
- hero.defend();
- if (hero.health <= 0)
- {
- battleOn = false;
- cout << "You lost the fight!" << endl;
- }
- }
- break;
- case 2:
- battleOn = false;
- cout << "You run away from the fight!" << endl;
- default:
- cout << "Invalid choice. Try again." << endl;
- }
- }
- }
- void show_menu()
- {
- int choice;
- cout << "Welcome to Galactic Survivor!" << endl;
- cout << "1. Start New Game" << endl;
- cout << "0. Quit Game" << endl;
- cout << "Enter your choice: ";
- cin >> choice;
- switch (choice)
- {
- case 1:
- start_game();
- break;
- case 0:
- end_game();
- break;
- default:
- cout << "Invalid choice. Try again." << endl;
- }
- }
- };
- int main()
- {
- // Stworzenie bohatera
- Hero hero("John", 100, 10, 30);
- // Stworzenie surowców
- Resources resources(0, 0, 0);
- // Stworzenie gry
- Game game(hero, resources);
- // Symulacja bitwy
- game.show_menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement