M3IY0U

Untitled

Dec 12th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include "SkatGame.h"
  2. #include <ctime>
  3.  
  4.  
  5. SkatGame::SkatGame()
  6. {
  7.     int counter = 0;
  8.     for (auto i = 0; i < 4; i++) {
  9.         for (auto j = 0; j < 8; j++) {
  10.             deck[counter] = Card(static_cast<Suit>(i), static_cast<Face>(j));
  11.             counter++;
  12.         }
  13.     }
  14. }
  15.  
  16. void SkatGame::shuffle()
  17. {
  18.     srand(time(nullptr));
  19.     random_shuffle(begin(deck), end(deck));
  20. }
  21.  
  22. void SkatGame::deal()
  23. {
  24.     for (auto i = 0; i < 10; i++) {
  25.         player1[i] = deck[i];
  26.     }
  27.     auto c = 0;
  28.     for (auto i = 10; i < 20; i++) {
  29.         player2[c] = deck[i];
  30.         c++;
  31.     }
  32.     c = 0;
  33.     for (auto i = 20; i < 30; i++) {
  34.         player3[c] = deck[i];
  35.         c++;
  36.     }
  37.     skat[0] = deck[30];
  38.     skat[1] = deck[31];
  39.     for (auto i = 0; i < 10; i++) {//sort player1
  40.         for (auto j = 0; j < 9; j++) {
  41.             if (player1[j].getSuit() > player1[j + 1].getSuit()) {
  42.                 Card temp = player1[j];
  43.                 player1[j] = player1[j + 1];
  44.                 player1[j + 1] = temp;
  45.             }
  46.             else if (player1[j].getSuit() == player1[j + 1].getSuit() && player1[j].getFace() > player1[j + 1].getFace()) {
  47.                 Card temp2 = player1[j];
  48.                 player1[j] = player1[j + 1];
  49.                 player1[j + 1] = temp2;
  50.             }
  51.         }
  52.     }
  53.     for (auto i = 0; i < 10; i++) {//sort player2
  54.         for (auto j = 0; j < 9; j++) {
  55.             if (player2[j].getSuit() > player2[j + 1].getSuit()) {
  56.                 Card temp = player2[j];
  57.                 player2[j] = player2[j + 1];
  58.                 player2[j + 1] = temp;
  59.             }
  60.             else if (player2[j].getSuit() == player2[j + 1].getSuit() && player2[j].getFace() > player2[j + 1].getFace()) {
  61.                 Card temp2 = player2[j];
  62.                 player2[j] = player2[j + 1];
  63.                 player2[j + 1] = temp2;
  64.             }
  65.         }
  66.     }
  67.     for (auto i = 0; i < 10; i++) {//sort player3
  68.         for (auto j = 0; j < 9; j++) {
  69.             if (player3[j].getSuit() > player3[j + 1].getSuit()) {
  70.                 Card temp = player3[j];
  71.                 player3[j] = player3[j + 1];
  72.                 player3[j + 1] = temp;
  73.             }
  74.             else if (player3[j].getSuit() == player3[j + 1].getSuit() && player3[j].getFace() > player3[j + 1].getFace()) {
  75.                 Card temp2 = player3[j];
  76.                 player3[j] = player3[j + 1];
  77.                 player3[j + 1] = temp2;
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. std::string SkatGame::toString()
  84. {
  85.     std::string player1S;
  86.     std::string player2S;
  87.     std::string player3S;
  88.     const std::string skatS = "\t" + skat[0].toString() + "\n" + "\t" + skat[1].toString();
  89.     for (auto i = 0; i < 10; i++) {
  90.         player1S =  player1S + "\t" + player1[i].toString() + "\n";
  91.     }
  92.  
  93.     for (auto i = 0; i < 10; i++) {
  94.         player2S = player2S + "\t" + player2[i].toString() + "\n";
  95.     }
  96.  
  97.     for (auto i = 0; i < 10; i++) {
  98.         player3S = player3S + "\t" + player3[i].toString() + "\n";
  99.     }
  100.  
  101.     std::string result = "Karten Player 1:\n\n" + player1S + " \n\n\n" + "Karten Player 2:\n\n" + player2S + "\n\n\n" + "Karten Player 3:\n\n" + player3S + "\n\n\n" + "Skatdeck:\n\n" + skatS + "\n";
  102.    
  103.     return result;
  104. }
  105.  
  106. std::array<Card, skatSize> SkatGame::getSkat()
  107. {
  108.     return skat;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment