Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Dawid Grzeszuk informatyka stacjonarne grupa 3a
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- class gracz
- {
- friend class talia;
- private:
- string imie;
- int figury[8];
- int kolory[8];
- public:
- void wpisywanie_imie(string wartosc)
- {
- this->imie = wartosc;
- }
- string wypisywanie_imie()
- {
- return imie;
- }
- };
- class karta
- {
- private:
- int id;
- int figura;
- int kolor;
- public:
- void wpisywanie_wartosci(int a, int b, int c)
- {
- this->id = a;
- this->figura = b;
- this->kolor = c;
- }
- int zwroc_id()
- {
- return id;
- }
- int zwroc_figura()
- {
- return figura;
- }
- int zwroc_kolor()
- {
- return kolor;
- }
- };
- class talia
- {
- friend class gracz;
- friend class karta;
- friend class gra;
- private:
- int ilosc_graczy;
- public:
- void tasowanie_kart(karta**&tab)
- {
- int temp[52];
- karta *temp2[52];
- for (int x = 0; x < 52; x++)
- {
- temp[x] = x;
- }
- random_shuffle(begin(temp), end(temp));
- for (int x = 0; x < 52; x++)
- {
- temp2[x] = tab[x];
- }
- for (int x = 0; x < 52; x++)
- {
- tab[x] = temp2[temp[x]];
- }
- cout << ("przetasowano karty") << endl;
- }
- void rozdawanie_kart(gracz **&tab_graczy, karta **&tab_kart)
- {
- int zmienna2 = 0;
- for (int zmienna = 0; zmienna<8; zmienna++)
- {
- for (int x = 0; x < ilosc_graczy; x++)
- {
- tab_graczy[x]->figury[zmienna] = tab_kart[zmienna2]->zwroc_figura();
- tab_graczy[x]->kolory[zmienna] = tab_kart[zmienna2]->zwroc_kolor();
- zmienna2++;
- }
- }
- }
- void wyswietlanie_kart(gracz **&tab_graczy, karta **&tab_kart)
- {
- string tab[13]{ "2","3","4","5","6","7","8","9","10","J","D","K","A" };
- for (int zmienna = 0; zmienna < ilosc_graczy; zmienna++)
- {
- cout << endl << tab_graczy[zmienna]->imie << (": ");
- for (int x = 0; x < 8; x++)
- {
- cout << tab[tab_graczy[zmienna]->figury[x]];
- switch(tab_graczy[zmienna]->kolory[x])
- {
- case 0:
- {
- cout << "\x3" << " ";
- break;
- }
- case 1:
- {
- cout << "\x4" << " ";
- break;
- }
- case 2:
- {
- cout << "\x5" << " ";
- break;
- }
- case 3:
- {
- cout << "\x6" << " ";
- break;
- }
- }
- }
- }
- cout << endl << endl << ("rozdano karty") << endl;
- }
- };
- class gra
- {
- friend class talia;
- private:
- gracz **lista_graczy;
- karta **lista_kart;
- talia dostep;
- int ilosc_graczy;
- public:
- void ilosc_graczy_wpisz(int wartosc)
- {
- this->ilosc_graczy = wartosc;
- dostep.ilosc_graczy = wartosc;
- }
- void stworz_graczy()
- {
- lista_graczy = new gracz*[ilosc_graczy];
- string imie;
- for (int x = 0; x < ilosc_graczy; x++)
- {
- gracz *nowy = new gracz;
- cout << ("podaj imie ") << x + 1 << (" gracza: ");
- cin >> imie;
- nowy->wpisywanie_imie(imie);
- lista_graczy[x] = nowy;
- }
- cout << endl << ("stworzono graczy") << endl;
- stworz_talie();
- }
- void stworz_talie()
- {
- lista_kart = new karta*[52];
- int y = 0;
- int z = 0;
- for (int x = 0; x < 52; x++)
- {
- karta *nowa = new karta;
- nowa->wpisywanie_wartosci(x, y, z);
- lista_kart[x] = nowa;
- y++;
- if (y == 13)
- {
- y = 0;
- z++;
- }
- }
- cout << ("stworzono talie") << endl;
- dostep.tasowanie_kart(lista_kart);
- dostep.rozdawanie_kart(lista_graczy, lista_kart);
- dostep.wyswietlanie_kart(lista_graczy, lista_kart);
- }
- };
- int main()
- {
- gra dostep;
- int ilosc;
- cout << ("podaj ilosc graczy: ");
- cin >> ilosc;
- dostep.ilosc_graczy_wpisz(ilosc);
- dostep.stworz_graczy();
- return 0;
- }
- //Dawid Grzeszuk informatyka stacjonarne grupa 3a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement