Advertisement
Cassimus

Rpg_refactor

Mar 12th, 2025
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <Windows.h>
  5. #include <cstdlib>
  6. #include <time.h>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. void display_menu(bool room_discovered[], string room_description[], int lenght)
  12. {
  13.     for (int i=0; i< lenght; i++)
  14.     {
  15.         if(room_discovered[i])
  16.         {
  17.             cout << i+1 <<". "<< room_description[i] << endl;
  18.         }
  19.         else
  20.         {
  21.             cout << i+1 << ". Nieznane pomieszczenie" << endl;
  22.         }
  23.     }
  24. }
  25.  
  26. int fight(string attacker, string defender, int attack)
  27. {
  28.     cout << attacker << " atakuje " << defender << " z siłą " << attack << endl;
  29.     Sleep(100);
  30.     return attack;
  31. }
  32.  
  33. int main()
  34. {
  35.     SetConsoleOutputCP(65001); // strona kodowa na polskie znaki
  36.     int health_player = 100;
  37.     int health_enemy{};
  38.     int enemy_killed{};
  39.     bool sealFounded = false;
  40.     bool is_victory = false; // stan gry
  41.  
  42.     bool room_discovered[] = {false, false, false};
  43.     string room_description[] = {"Komnata leczenia", "Pokój strażnika", "Komnata bossa"};
  44.  
  45.     int choice = 0;
  46.  
  47.     srand(time(nullptr));
  48.  
  49.     cout << "Jesteście śmiałkami którzy trafili do legendarnego lochu Nexraxonu. ";
  50.     cout << "Musicie pokonać Ahzoga plugawiciela dusz aby zdobyć legendarny skarb. ";
  51.     cout << "Jednak droga niejest łatwa, loch jest najeżony wieloma pułapkami, a dostępu ";
  52.     cout << "do Ahzoga pilnują jego wierni słudzy których należy pokonać.\n\n";
  53.  
  54.     while (health_player > 0 && !is_victory)
  55.     {
  56.         // funkcja display_stats
  57.         printf("Twoje życie wynosi %d \nStażnikow pokonanych %d \nOdkrytych pieczęci %d\n",
  58.                health_player, enemy_killed, sealFounded);
  59.         cout << endl;
  60.  
  61.         // display_menu
  62.         cout << "Widzisz trzy pomieszczenia. Do ktorego chesz iść? " << endl;
  63.         display_menu(room_discovered, room_description, 3);
  64.  
  65.         cin >> choice;
  66.  
  67.         switch (choice)
  68.         {
  69.         case 1:
  70.             room_discovered[0] = true;
  71.             cout << "Wchodzisz do komnaty leczenia. Twoje zdrowie wzrasta do 100" << endl;
  72.             health_player = 100;
  73.             break;
  74.         case 2:
  75.             room_discovered[1] = true;
  76.             cout << "Atakuje cie strażnik pieczęci, Gradon \n";
  77.             health_enemy = rand() % 31 + 40;
  78.  
  79.             while (health_enemy >0 && health_player > 0)
  80.             {
  81.                 // fight(kto, kogo, wartość_ataku)
  82.                 int enemy_attack = rand()%5 + 3;
  83.                 int player_attack = rand()%5 + 3;
  84.  
  85.                 health_player -= enemy_attack;
  86.                 health_enemy -= player_attack;
  87.             }
  88.            
  89.             break;
  90.         case 3:
  91.             room_discovered[2] = true;
  92.             break;
  93.  
  94.         default:
  95.             cout <<  "Nieznane pomieszczenie \n";
  96.             break;
  97.         }
  98.     }
  99.  
  100.     return 0;
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement