Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SkatGame.h"
- #include <ctime>
- SkatGame::SkatGame()
- {
- int counter = 0;
- for (auto i = 0; i < 4; i++) {
- for (auto j = 0; j < 8; j++) {
- deck[counter] = Card(static_cast<Suit>(i), static_cast<Face>(j));
- counter++;
- }
- }
- }
- void SkatGame::shuffle()
- {
- srand(time(nullptr));
- random_shuffle(begin(deck), end(deck));
- }
- void SkatGame::deal()
- {
- for (auto i = 0; i < 10; i++) {
- player1[i] = deck[i];
- }
- auto c = 0;
- for (auto i = 10; i < 20; i++) {
- player2[c] = deck[i];
- c++;
- }
- c = 0;
- for (auto i = 20; i < 30; i++) {
- player3[c] = deck[i];
- c++;
- }
- skat[0] = deck[30];
- skat[1] = deck[31];
- for (auto i = 0; i < 10; i++) {//sort player1
- for (auto j = 0; j < 9; j++) {
- if (player1[j].getSuit() > player1[j + 1].getSuit()) {
- Card temp = player1[j];
- player1[j] = player1[j + 1];
- player1[j + 1] = temp;
- }
- else if (player1[j].getSuit() == player1[j + 1].getSuit() && player1[j].getFace() > player1[j + 1].getFace()) {
- Card temp2 = player1[j];
- player1[j] = player1[j + 1];
- player1[j + 1] = temp2;
- }
- }
- }
- for (auto i = 0; i < 10; i++) {//sort player2
- for (auto j = 0; j < 9; j++) {
- if (player2[j].getSuit() > player2[j + 1].getSuit()) {
- Card temp = player2[j];
- player2[j] = player2[j + 1];
- player2[j + 1] = temp;
- }
- else if (player2[j].getSuit() == player2[j + 1].getSuit() && player2[j].getFace() > player2[j + 1].getFace()) {
- Card temp2 = player2[j];
- player2[j] = player2[j + 1];
- player2[j + 1] = temp2;
- }
- }
- }
- for (auto i = 0; i < 10; i++) {//sort player3
- for (auto j = 0; j < 9; j++) {
- if (player3[j].getSuit() > player3[j + 1].getSuit()) {
- Card temp = player3[j];
- player3[j] = player3[j + 1];
- player3[j + 1] = temp;
- }
- else if (player3[j].getSuit() == player3[j + 1].getSuit() && player3[j].getFace() > player3[j + 1].getFace()) {
- Card temp2 = player3[j];
- player3[j] = player3[j + 1];
- player3[j + 1] = temp2;
- }
- }
- }
- }
- std::string SkatGame::toString()
- {
- std::string player1S;
- std::string player2S;
- std::string player3S;
- const std::string skatS = "\t" + skat[0].toString() + "\n" + "\t" + skat[1].toString();
- for (auto i = 0; i < 10; i++) {
- player1S = player1S + "\t" + player1[i].toString() + "\n";
- }
- for (auto i = 0; i < 10; i++) {
- player2S = player2S + "\t" + player2[i].toString() + "\n";
- }
- for (auto i = 0; i < 10; i++) {
- player3S = player3S + "\t" + player3[i].toString() + "\n";
- }
- 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";
- return result;
- }
- std::array<Card, skatSize> SkatGame::getSkat()
- {
- return skat;
- }
Advertisement
Add Comment
Please, Sign In to add comment