Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // blackjack.txt - Purpose: To play blackjack against a computer opponent
- // Scott Hancock
- // CISP 360
- // December 11, 2015
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int suit;
- int card;
- int ace;
- int currentCount;
- int changeCard;
- int previousChanges;
- int cardCount = 0;
- int newSuit;
- int newCard;
- string draw = "y";
- string tcard[13] =
- { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
- string tsuit[4] =
- { "Diamonds", "Hearts", "Spades", "Clubs" };
- string cards[4][13] = {
- { "Diamonds", "Hearts", "Spades", "Clubs" },
- { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" }
- };
- string currentCards[5];
- void drawingCards()
- {
- newSuit = rand() % 4;;
- suit=newSuit;
- newCard = rand() % 13;
- card = newCard;
- if (cards[newSuit][newCard] != "used")
- {
- cardCount = cardCount + 1;
- ///////add card to total//////////////////
- if (newCard == 0)
- {
- currentCount = currentCount + 11;
- draw = "n";
- ace = ace + 1;
- if (currentCount > 21)
- {
- currentCount = currentCount - 10;
- ace = ace - 1;
- }
- }
- if ((newCard == 10) || (newCard == 11) || (newCard == 12))
- {
- currentCount = currentCount + 10;
- draw = "n";
- }
- if (newCard == 1)
- {
- currentCount = currentCount + 2;
- draw = "n";
- }
- if (newCard == 2)
- {
- currentCount = currentCount + 3;
- draw = "n";
- }
- if (newCard == 3)
- {
- currentCount = currentCount + 4;
- draw = "n";
- }
- if (newCard == 4)
- {
- currentCount = currentCount + 5;
- draw = "n";
- }
- if (newCard == 5)
- {
- currentCount = currentCount + 6;
- draw = "n";
- }
- if (newCard == 6)
- {
- currentCount = currentCount + 7;
- draw = "n";
- }
- if (newCard == 7)
- {
- currentCount = currentCount + 8;
- draw = "n";
- }
- if (newCard == 8)
- {
- currentCount = currentCount + 9;
- draw = "n";
- }
- if (newCard == 9)
- {
- currentCount = currentCount + 10;
- draw = "n";
- }
- ///////////////////////// End of adding card to total ///////////////////
- cout << "You recieved: " << tcard[newCard] << " of " << tsuit[newSuit] << endl;
- cards[newSuit][newCard] = "used";
- if (currentCount > 21)
- {
- if (ace > 0)
- {
- currentCount = currentCount - 10;
- ace = ace - 1;
- }
- else
- {
- cout << "You busted!" << endl;
- }
- }
- if (currentCount == 21)
- {
- if (cardCount == 2)
- {
- cout << "Blackjack!" << endl;
- }
- else
- {
- cout << "You have 21!" << endl;
- }
- }
- if ((currentCount < 21) && (cardCount < 2 ))
- {
- draw = "y";
- }
- if ((currentCount < 21) && (cardCount >= 2 ))
- {
- cout << "Your total is: " << currentCount << ". Would you like another card? (y/n)" << endl;
- cin >> draw;
- }
- }
- }
- int main()
- {
- srand( time(0) );
- while (draw == "y")
- {
- drawingCards();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement