Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- class Set
- {
- int punkty;
- int punkty2;
- string druzyna1;
- string druzyna2;
- short n;
- public:
- void p();
- void wypisz();
- short trwa();
- void graj_set();
- Set(string, string, short);
- };
- Set::Set(string a, string b, short p) : punkty(0), punkty2(0), druzyna1(a), druzyna2(b), n(p) {}
- void Set::p()
- {
- srand(time(nullptr));
- if(rand() % 2 == 0)
- punkty++ ;
- else
- punkty2++ ;
- }
- void Set::wypisz()
- {
- cout << druzyna1 << ' ' << punkty << ':';
- cout << punkty2 << ' ' << druzyna2 << endl;
- }
- short Set::trwa()
- {
- if( punkty >= n && (punkty - punkty2) > 1)
- return 1;
- if( punkty2 >= n && (punkty2 - punkty) > 1)
- return 2;
- return 0;
- }
- void Set::graj_set()
- {
- while(trwa() == 0)
- {
- _getch();
- p();
- wypisz();
- }
- if(trwa() == 1)
- cout << "Set wygrany przez " << druzyna1 << " wynikiem " << punkty << ':' << punkty2 << endl;
- _getch();
- }
- class Mecz
- {
- string druzyna1;
- string druzyna2;
- int w_druzyna1;
- int w_druzyna2;
- short ktory_set;
- Set *wygrane[5];
- public:
- void graj();
- Mecz(string, string);
- ~Mecz();
- };
- Mecz::Mecz(string a, string b) : druzyna1(a), druzyna2(b), w_druzyna1(0), w_druzyna2(0), ktory_set(1)
- {
- for(short i = 0; i < 5; ++i)
- wygrane[i] = nullptr;
- }
- Mecz::~Mecz()
- {
- for(short i = 0; i < 5; ++i)
- if(wygrane[i] != nullptr)
- delete wygrane[i];
- }
- void Mecz::graj()
- {
- while(w_druzyna1 < 3 && w_druzyna2 < 3)
- {
- if(ktory_set < 5)
- wygrane[ktory_set - 1] = new Set(druzyna1, druzyna2, 25);
- else
- wygrane[ktory_set - 1] = new Set(druzyna1, druzyna2, 15);
- cout << "Set " << ktory_set << endl;
- wygrane[ktory_set - 1]->graj_set();
- if(wygrane[ktory_set - 1]->trwa() == 1)
- ++w_druzyna1;
- else
- ++w_druzyna2;
- cout << druzyna1 << ' ' << w_druzyna1 << ':' << w_druzyna2 << ' ' << druzyna2 << endl;
- _getch();
- ++ktory_set;
- }
- }
- int main()
- {
- string a, b;
- cout << "podaj nazwe druzyny" << endl;
- getline(cin, a);
- cout << "podaj nazwe 2 druzyny" << endl;
- getline(cin, b);
- Mecz mecz(a, b);
- mecz.graj();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement