Advertisement
isotonicq

Untitled

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