SHARE
TWEET

Untitled

a guest Apr 26th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <string.h>
  5. #include <vector>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. typedef vector<string> deck;
  11.  
  12. void giveCard(unsigned short &pScore, deck &aDeck, int activePlayer);
  13.  
  14. int main()
  15. {
  16.     setlocale(LC_ALL, "ru");
  17.  
  18.     deck spades  =  { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
  19.     deck diamods =  { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
  20.     deck hearts  =  { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
  21.     deck clubs   =  { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
  22.     deck *decksArray[4] = { &spades, &diamods, &hearts, &clubs };
  23.  
  24.     srand(time(NULL));
  25.     bool isFPlayerWinner = false;
  26.     bool isSPlayerWinner = false;
  27.     unsigned short fpScore = 0; // Количество очков первого игрока
  28.     unsigned short spScore = 0; // Количество очков второго игрока
  29.     unsigned short scoresGained; //Количество очков которое получил игрок, когда вытянул карту
  30.     int activeDeckIndex = rand() % 4;
  31.     deck *activeDeck = decksArray[activeDeckIndex];
  32.  
  33.     cout << "Нажмите [Enter] чтобы начать игру";
  34.     cin.ignore(256, '\n');
  35.     cout << endl;
  36.  
  37.     while (!isFPlayerWinner && !isSPlayerWinner)
  38.     {
  39.         cout << "Ходит первый игрок " << endl;
  40.         scoresGained = fpScore;
  41.         giveCard(fpScore, *activeDeck, 1);
  42.         scoresGained = fpScore - scoresGained;
  43.         cout << "\nИгрок 1 получает " << scoresGained << " очков!";
  44.         cout << "\nУ игрока 1 теперь " << fpScore << " очков" << endl << endl;
  45.  
  46.         if (fpScore == 21 || spScore > 21)
  47.         {
  48.             isFPlayerWinner = true;
  49.             break;
  50.         }
  51.         else if (spScore == 21 || fpScore > 21)
  52.         {
  53.             isSPlayerWinner = true;
  54.             break;
  55.         }
  56.  
  57.         cout << "Нажмите [Enter] чтобы продолжить";
  58.         cin.ignore(256, '\n');
  59.         cout << endl;
  60.  
  61.         cout << "Ходит второй игрок " << endl;
  62.         scoresGained = spScore;
  63.         giveCard(spScore, *activeDeck, 2);
  64.         scoresGained = spScore - scoresGained;
  65.         cout << "\nИгрок 2 получает " << scoresGained << " очков!";
  66.         cout << "\nУ игрока 2 теперь " << spScore << " очков" << endl << endl;
  67.  
  68.         activeDeckIndex = rand() % 4;
  69.         activeDeck = decksArray[activeDeckIndex];
  70.  
  71.         if (fpScore == 21 || spScore > 21)
  72.         {
  73.             isFPlayerWinner = true;
  74.             break;
  75.         }
  76.         else if (spScore == 21 || fpScore > 21)
  77.         {
  78.             isSPlayerWinner = true;
  79.             break;
  80.         }
  81.  
  82.         cout << "Нажмите [Enter] чтобы продолжить";
  83.         cin.ignore(256, '\n');
  84.         cout << endl;
  85.     }
  86.  
  87.     if (isFPlayerWinner)
  88.         cout << "Игрок 1 побеждает!" << endl;
  89.     else
  90.         cout << "Игрок 2 побеждает!" << endl;
  91. }
  92.  
  93. void giveCard(unsigned short& pScore, deck& aDeck, int activePlayer)
  94. {
  95.     int card = rand() % aDeck.size();
  96.     if (activePlayer == 1)
  97.         cout << "Игрок 1 вытягивает карту " << aDeck.at(card);
  98.     else if (activePlayer == 2)
  99.         cout << "Игрок 2 вытягивает карту " << aDeck.at(card);
  100.  
  101.     if (aDeck[card] == "6")
  102.         pScore += 6;
  103.     else if (aDeck[card] == "7")
  104.         pScore += 7;
  105.     else if (aDeck[card] == "8")
  106.         pScore += 8;
  107.     else if (aDeck[card] == "9")
  108.         pScore += 9;
  109.     else if (aDeck[card] == "10")
  110.         pScore += 10;
  111.     else if (aDeck[card] == "Jack")
  112.         pScore += 11;
  113.     else if (aDeck[card] == "Queen")
  114.         pScore += 12;
  115.     else if (aDeck[card] == "King")
  116.         pScore += 13;
  117.     else if (aDeck[card] == "Ace")
  118.         pScore += 14;
  119.     aDeck.erase(aDeck.begin() + card);
  120. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top