Advertisement
MeehoweCK

Untitled

Apr 12th, 2021
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. class Set
  8. {
  9.     int punkty;
  10.     int punkty2;
  11.     string druzyna1;
  12.     string druzyna2;
  13.     short n;
  14. public:
  15.     void p();
  16.     void wypisz();
  17.     short trwa();
  18.     void graj_set();
  19.     Set(string, string, short);
  20. };
  21.  
  22. Set::Set(string a, string b, short p) : punkty(0), punkty2(0), druzyna1(a), druzyna2(b), n(p) {}
  23.  
  24. void Set::p()
  25. {
  26.     srand(time(nullptr));
  27.     if(rand() % 2 == 0)
  28.         punkty++ ;
  29.     else
  30.         punkty2++ ;
  31.  
  32. }
  33. void Set::wypisz()
  34. {
  35.     cout << druzyna1 << ' ' << punkty << ':';
  36.     cout << punkty2  << ' ' << druzyna2 << endl;
  37. }
  38.  
  39. short Set::trwa()
  40. {
  41.     if( punkty >= n && (punkty - punkty2) > 1)
  42.         return 1;
  43.     if( punkty2 >= n && (punkty2 - punkty) > 1)
  44.         return 2;
  45.     return 0;
  46. }
  47.  
  48. void Set::graj_set()
  49. {
  50.     while(trwa() == 0)
  51.     {
  52.         _getch();
  53.         p();
  54.         wypisz();
  55.     }
  56.     if(trwa() == 1)
  57.         cout << "Set wygrany przez " << druzyna1 << " wynikiem " << punkty << ':' << punkty2 << endl;
  58.     _getch();
  59. }
  60.  
  61. class Mecz
  62. {
  63.     string druzyna1;
  64.     string druzyna2;
  65.     int w_druzyna1;
  66.     int w_druzyna2;
  67.     short ktory_set;
  68.     Set *wygrane[5];
  69. public:
  70.     void graj();
  71.     Mecz(string, string);
  72.     ~Mecz();
  73. };
  74.  
  75. Mecz::Mecz(string a, string b) : druzyna1(a), druzyna2(b), w_druzyna1(0), w_druzyna2(0), ktory_set(1)
  76. {
  77.     for(short i = 0; i < 5; ++i)
  78.         wygrane[i] = nullptr;
  79. }
  80.  
  81. Mecz::~Mecz()
  82. {
  83.     for(short i = 0; i < 5; ++i)
  84.         if(wygrane[i] != nullptr)
  85.             delete wygrane[i];
  86. }
  87.  
  88. void Mecz::graj()
  89. {
  90.     while(w_druzyna1 < 3 && w_druzyna2 < 3)
  91.     {
  92.         if(ktory_set < 5)
  93.             wygrane[ktory_set - 1] = new Set(druzyna1, druzyna2, 25);
  94.         else
  95.             wygrane[ktory_set - 1] = new Set(druzyna1, druzyna2, 15);
  96.         cout << "Set " << ktory_set << endl;
  97.         wygrane[ktory_set - 1]->graj_set();
  98.         if(wygrane[ktory_set - 1]->trwa() == 1)
  99.             ++w_druzyna1;
  100.         else
  101.             ++w_druzyna2;
  102.         cout << druzyna1 << ' ' << w_druzyna1 << ':' << w_druzyna2 << ' ' << druzyna2 << endl;
  103.         _getch();
  104.         ++ktory_set;
  105.     }
  106. }
  107.  
  108. int main()
  109. {
  110.     string a, b;
  111.     cout << "podaj nazwe druzyny" << endl;
  112.     getline(cin, a);
  113.     cout << "podaj nazwe 2 druzyny" << endl;
  114.     getline(cin, b);
  115.  
  116.     Mecz mecz(a, b);
  117.     mecz.graj();
  118.  
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement