Advertisement
isotonicq

Untitled

Mar 23rd, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.60 KB | None | 0 0
  1. //Dawid Grzeszuk informatyka stacjonarne grupa 3a
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. class gracz
  10. {
  11.     friend class talia;
  12. private:
  13.     string imie;
  14.     int figury[8];
  15.     int kolory[8];
  16. public:
  17.     void wpisywanie_imie(string wartosc)
  18.     {
  19.         this->imie = wartosc;
  20.     }
  21.     string wypisywanie_imie()
  22.     {
  23.         return imie;
  24.     }
  25. };
  26.  
  27. class karta
  28. {
  29. private:
  30.     int id;
  31.     int figura;
  32.     int kolor;
  33. public:
  34.     void wpisywanie_wartosci(int a, int b, int c)
  35.     {
  36.         this->id = a;
  37.         this->figura = b;
  38.         this->kolor = c;
  39.     }
  40.     int zwroc_id()
  41.     {
  42.         return id;
  43.     }
  44.     int zwroc_figura()
  45.     {
  46.         return figura;
  47.     }
  48.     int zwroc_kolor()
  49.     {
  50.         return kolor;
  51.     }
  52. };
  53.  
  54. class talia
  55. {
  56.     friend class gracz;
  57.     friend class karta;
  58.     friend class gra;
  59.  
  60. private:
  61.     int ilosc_graczy;
  62.  
  63. public:
  64.    
  65.     void tasowanie_kart(karta**&tab)
  66.     {
  67.         int temp[52];
  68.         karta *temp2[52];
  69.  
  70.         for (int x = 0; x < 52; x++)
  71.         {
  72.             temp[x] = x;
  73.         }
  74.  
  75.         random_shuffle(begin(temp), end(temp));
  76.  
  77.         for (int x = 0; x < 52; x++)
  78.         {
  79.             temp2[x] = tab[x];
  80.         }
  81.  
  82.         for (int x = 0; x < 52; x++)
  83.         {
  84.             tab[x] = temp2[temp[x]];
  85.         }
  86.         cout << ("przetasowano karty") << endl;
  87.     }
  88.  
  89.     void rozdawanie_kart(gracz **&tab_graczy, karta **&tab_kart)
  90.     {
  91.         int zmienna2 = 0;
  92.  
  93.         for (int zmienna = 0; zmienna<8; zmienna++)
  94.         {
  95.             for (int x = 0; x < ilosc_graczy; x++)
  96.             {
  97.                 tab_graczy[x]->figury[zmienna] = tab_kart[zmienna2]->zwroc_figura();
  98.                 tab_graczy[x]->kolory[zmienna] = tab_kart[zmienna2]->zwroc_kolor();
  99.                 zmienna2++;
  100.             }
  101.         }
  102.     }
  103.  
  104.     void wyswietlanie_kart(gracz **&tab_graczy, karta **&tab_kart)
  105.     {
  106.         string tab[13]{ "2","3","4","5","6","7","8","9","10","J","D","K","A" };
  107.  
  108.         for (int zmienna = 0; zmienna < ilosc_graczy; zmienna++)
  109.         {
  110.             cout << endl << tab_graczy[zmienna]->imie << (": ");
  111.             for (int x = 0; x < 8; x++)
  112.             {
  113.                 cout << tab[tab_graczy[zmienna]->figury[x]];
  114.                 switch(tab_graczy[zmienna]->kolory[x])
  115.                 {
  116.                 case 0:
  117.                 {
  118.                     cout << "\x3" << " ";
  119.                     break;
  120.                 }
  121.                 case 1:
  122.                 {
  123.                     cout << "\x4" << " ";
  124.                     break;
  125.                 }
  126.                 case 2:
  127.                 {
  128.                     cout << "\x5" << " ";
  129.                     break;
  130.                 }
  131.                 case 3:
  132.                 {
  133.                     cout << "\x6" << " ";
  134.                     break;
  135.                 }
  136.  
  137.                 }
  138.             }
  139.         }
  140.  
  141.         cout << endl << endl << ("rozdano karty") << endl;
  142.     }
  143. };
  144.  
  145. class gra
  146. {
  147.     friend class talia;
  148. private:
  149.     gracz **lista_graczy;
  150.     karta **lista_kart;
  151.     talia dostep;
  152.     int ilosc_graczy;
  153.  
  154. public:
  155.     void ilosc_graczy_wpisz(int wartosc)
  156.     {
  157.         this->ilosc_graczy = wartosc;
  158.         dostep.ilosc_graczy = wartosc;
  159.     }
  160.  
  161.     void stworz_graczy()
  162.     {
  163.         lista_graczy = new gracz*[ilosc_graczy];
  164.         string imie;
  165.  
  166.         for (int x = 0; x < ilosc_graczy; x++)
  167.         {
  168.             gracz *nowy = new gracz;
  169.             cout << ("podaj imie ") << x + 1 << (" gracza: ");
  170.             cin >> imie;
  171.             nowy->wpisywanie_imie(imie);
  172.             lista_graczy[x] = nowy;
  173.         }
  174.  
  175.         cout << endl << ("stworzono graczy") << endl;
  176.         stworz_talie();
  177.     }
  178.  
  179.     void stworz_talie()
  180.     {
  181.         lista_kart = new karta*[52];
  182.         int y = 0;
  183.         int z = 0;
  184.  
  185.         for (int x = 0; x < 52; x++)
  186.         {
  187.             karta *nowa = new karta;
  188.             nowa->wpisywanie_wartosci(x, y, z);
  189.             lista_kart[x] = nowa;
  190.  
  191.             y++;
  192.  
  193.             if (y == 13)
  194.             {
  195.                 y = 0;
  196.                 z++;
  197.             }
  198.         }
  199.         cout << ("stworzono talie") << endl;
  200.         dostep.tasowanie_kart(lista_kart);
  201.         dostep.rozdawanie_kart(lista_graczy, lista_kart);
  202.         dostep.wyswietlanie_kart(lista_graczy, lista_kart);
  203.     }
  204. };
  205.  
  206. int main()
  207. {
  208.     gra dostep;
  209.     int ilosc;
  210.  
  211.     cout << ("podaj ilosc graczy: ");
  212.     cin >> ilosc;
  213.  
  214.     dostep.ilosc_graczy_wpisz(ilosc);
  215.     dostep.stworz_graczy();
  216.  
  217.     return 0;
  218. }
  219. //Dawid Grzeszuk informatyka stacjonarne grupa 3a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement