Untitled
unknown
plain_text
2 years ago
2.9 kB
8
Indexable
#include <iostream> #include "blackjack.h" using namespace std; int main() { // cards must be represented using the following string array string cards[52] = {"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH", "AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD", "AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS", "AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC"}; // shuffle cards shuffleCards(cards, 52); // Player's turn string playerHand[20] = {}; playerHand[0] = cards[0]; playerHand[1] = cards[1]; int cardsUsed = 1; int numberOfCardsInPlayerHand = 2; int totalScore = 0; totalScore += calculatePoints(playerHand, numberOfCardsInPlayerHand); int tempScore = 0; system("clear"); cout << endl; cout << "Your Hand: " << totalScore << endl; cout << endl; printHand(playerHand, 2); while (true) { cout << endl; cout << "Continue ([Y]/N): "; //cout << endl; string c; getline(cin, c); if (toupper(c[0]) == 'N') { break; } playerHand[cardsUsed+1] = cards[cardsUsed+1]; totalScore = calculatePoints(playerHand, numberOfCardsInPlayerHand+1); system("clear"); cout << endl; cout << "Your Hand: " << totalScore << endl; cout << endl; printHand(playerHand, numberOfCardsInPlayerHand+1); numberOfCardsInPlayerHand++; cardsUsed++; if (totalScore >= 21){ break; } } //dealers turn string dealerHand[20] = {}; int dealerHandIndexCounter = 0; dealerHand[dealerHandIndexCounter] = cards[cardsUsed+1]; int dealerScore = calculatePoints(dealerHand, dealerHandIndexCounter+1); while (true) { cardsUsed++; dealerHandIndexCounter++; if (dealerScore < 17){ for (int i = 0; i < dealerHandIndexCounter+1; i++) { if (dealerHand[i] == "AH" || playerHand[i] == "AD" || playerHand[i] == "AS" || playerHand[i] == "AC"){ if (dealerScore > 21){ dealerScore = dealerScore - 10; } } } dealerHand[dealerHandIndexCounter] = cards[cardsUsed+1]; dealerScore = calculatePoints(dealerHand, dealerHandIndexCounter+1); } else { break; } } cout << endl; cout << "Dealer's Hand: " << dealerScore << endl; cout << endl; printHand(dealerHand, dealerHandIndexCounter); // print outcome string endOfGame = determineOutcome(playerHand, numberOfCardsInPlayerHand+1, dealerHand, dealerHandIndexCounter); cout << endl; cout << endOfGame << endl; cout << endl; return 0; }
Editor is loading...
Leave a Comment