Advertisement
drakon-firestone

Untitled

May 21st, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <ctime>
  5. #include <random>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. enum KolorKarty {
  11. KIER,
  12. KARO,
  13. TREFL,
  14. PIK
  15. };
  16.  
  17. enum WartoscKarty
  18. {
  19. AS = 1,
  20. DWOJKA = 2,
  21. TROJKA = 3,
  22. CZWORKA = 4,
  23. PIATKA = 5,
  24. SZOSTKA = 6,
  25. SIODEMKA = 7,
  26. OSEMKA = 8,
  27. DZIEWIATKA = 9,
  28. DZIESIATKA = 10,
  29. WALET = 11,
  30. DAMA = 12,
  31. KROL = 13
  32. };
  33.  
  34. string WyswietlWartoscKarty(WartoscKarty wartosc)
  35. {
  36. if(wartosc == AS) return "A";
  37. if((int)wartosc > 1 && (int)wartosc < 11) return to_string(wartosc);
  38. if(wartosc == WALET) return "W";
  39. if(wartosc == DAMA) return "D";
  40. if(wartosc == KROL) return "K";
  41. }
  42.  
  43.  
  44. string WyswietlKolorKarty(KolorKarty kolor)
  45. {
  46. if(kolor == PIK) return "♠️";
  47. if(kolor == KARO) return "♦️";
  48. if(kolor == TREFL) return "♣️";
  49. if(kolor == KIER) return "♥️";
  50. }
  51.  
  52. class Karta {
  53. public:
  54. KolorKarty kolor;
  55. WartoscKarty wartosc;
  56. bool odslonieta;
  57.  
  58. Karta(WartoscKarty _wartosc, KolorKarty _kolor)
  59. {
  60. kolor = _kolor;
  61. wartosc = _wartosc;
  62. odslonieta = false;
  63. }
  64.  
  65. void Wyswietl()
  66. {
  67. cout << WyswietlWartoscKarty(wartosc) << WyswietlKolorKarty(kolor) << endl;
  68. }
  69.  
  70. bool odslon_karte()
  71. {
  72. odslonieta = true;
  73. }
  74. };
  75.  
  76.  
  77. ostream& operator<<(ostream& os, const Karta& karta)
  78. {
  79. if(karta.odslonieta)
  80. {
  81. string tekst = "";
  82. tekst += (karta.wartosc != DZIESIATKA) ? " " : "";
  83. tekst += WyswietlWartoscKarty(karta.wartosc) + WyswietlKolorKarty(karta.kolor);
  84. return os << tekst;
  85. }
  86. else
  87. {
  88. return os << " 🂠 ";
  89. }
  90.  
  91. }
  92.  
  93. int main()
  94. {
  95.  
  96. vector <Karta> talia;
  97.  
  98. KolorKarty kolory[] = {KARO, PIK, KIER, TREFL};
  99.  
  100. for(int i = 0; i < 4; i++)
  101. {
  102. for(int j = 1; j <= 13; j++)
  103. {
  104. talia.push_back(Karta((WartoscKarty)j, kolory[i]));
  105. }
  106. }
  107.  
  108.  
  109. shuffle(talia.begin(), talia.end(), default_random_engine(static_cast<unsigned>(time(nullptr))));
  110.  
  111. talia[14].odslon_karte();
  112. talia[38].odslon_karte();
  113. talia[51].odslon_karte();
  114.  
  115. for(int i = 0; i < talia.size(); i++)
  116. {
  117. cout << talia[i] << endl;
  118. }
  119.  
  120.  
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement