Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <string.h>
- #include <vector>
- #include <ctime>
- using namespace std;
- typedef vector<string> deck;
- void giveCard(unsigned short &pScore, deck &aDeck, int activePlayer);
- int main()
- {
- setlocale(LC_ALL, "ru");
- deck spades = { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
- deck diamods = { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
- deck hearts = { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
- deck clubs = { "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
- deck *decksArray[4] = { &spades, &diamods, &hearts, &clubs };
- srand(time(NULL));
- bool isFPlayerWinner = false;
- bool isSPlayerWinner = false;
- unsigned short fpScore = 0; // Количество очков первого игрока
- unsigned short spScore = 0; // Количество очков второго игрока
- unsigned short scoresGained; //Количество очков которое получил игрок, когда вытянул карту
- int activeDeckIndex = rand() % 4;
- deck *activeDeck = decksArray[activeDeckIndex];
- cout << "Нажмите [Enter] чтобы начать игру";
- cin.ignore(256, '\n');
- cout << endl;
- while (!isFPlayerWinner && !isSPlayerWinner)
- {
- cout << "Ходит первый игрок " << endl;
- scoresGained = fpScore;
- giveCard(fpScore, *activeDeck, 1);
- scoresGained = fpScore - scoresGained;
- cout << "\nИгрок 1 получает " << scoresGained << " очков!";
- cout << "\nУ игрока 1 теперь " << fpScore << " очков" << endl << endl;
- if (fpScore == 21 || spScore > 21)
- {
- isFPlayerWinner = true;
- break;
- }
- else if (spScore == 21 || fpScore > 21)
- {
- isSPlayerWinner = true;
- break;
- }
- cout << "Нажмите [Enter] чтобы продолжить";
- cin.ignore(256, '\n');
- cout << endl;
- cout << "Ходит второй игрок " << endl;
- scoresGained = spScore;
- giveCard(spScore, *activeDeck, 2);
- scoresGained = spScore - scoresGained;
- cout << "\nИгрок 2 получает " << scoresGained << " очков!";
- cout << "\nУ игрока 2 теперь " << spScore << " очков" << endl << endl;
- activeDeckIndex = rand() % 4;
- activeDeck = decksArray[activeDeckIndex];
- if (fpScore == 21 || spScore > 21)
- {
- isFPlayerWinner = true;
- break;
- }
- else if (spScore == 21 || fpScore > 21)
- {
- isSPlayerWinner = true;
- break;
- }
- cout << "Нажмите [Enter] чтобы продолжить";
- cin.ignore(256, '\n');
- cout << endl;
- }
- if (isFPlayerWinner)
- cout << "Игрок 1 побеждает!" << endl;
- else
- cout << "Игрок 2 побеждает!" << endl;
- }
- void giveCard(unsigned short& pScore, deck& aDeck, int activePlayer)
- {
- int card = rand() % aDeck.size();
- if (activePlayer == 1)
- cout << "Игрок 1 вытягивает карту " << aDeck.at(card);
- else if (activePlayer == 2)
- cout << "Игрок 2 вытягивает карту " << aDeck.at(card);
- if (aDeck[card] == "6")
- pScore += 6;
- else if (aDeck[card] == "7")
- pScore += 7;
- else if (aDeck[card] == "8")
- pScore += 8;
- else if (aDeck[card] == "9")
- pScore += 9;
- else if (aDeck[card] == "10")
- pScore += 10;
- else if (aDeck[card] == "Jack")
- pScore += 11;
- else if (aDeck[card] == "Queen")
- pScore += 12;
- else if (aDeck[card] == "King")
- pScore += 13;
- else if (aDeck[card] == "Ace")
- pScore += 14;
- aDeck.erase(aDeck.begin() + card);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement