1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
const int NUMCARDS=52;
const int STRLEN=25;
void showRules(int &Option2, int reshuffle, int playersAces, int dealersAces, int naturalTest, int choice1);
void shuffle1();
void shuffle2();
void getInitialCards(int reshuffle, int &playersAces, int &dealersAces, int &naturalTest, int choice1);
void displayCardsandTotals(int pTotal, int dTotal);
void hitORStay(int &choice1);
void bigProcess(int &naturalTest, int &pTotal, int &dTotal, int &playersAces, int &dealersAces, int reshuffle, int choice1);
void NewHand(int &naturalTest, int &playersAces, int &dealersAces, int pWins, int pLosses, int pTies);
void checkOption(int &Option1);
int cards[NUMCARDS];
char cardNames1[NUMCARDS];
char cardNames2[NUMCARDS][STRLEN] = { "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades",
"Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades",
"Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades", "Ace of Diamonds",
"Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds",
"Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds",
"Queen of Diamonds", "King of Diamonds", "Ace of Clubs", "Two of Clubs", "Three of Clubs",
"Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs",
"Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs", "Ace of Hearts", "Two of Hearts",
"Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts",
"Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"};
int main()
{
int Option1;
int Option2=0;
int playersAces=0;
int dealersAces=0;
int reshuffle;
char choice1=0;
int naturalTest=0;
shuffle2();
cout << "Please press 1 to view the rules for Blackjack.\n";
cout << "Please press 2 to skip the rules and just play!\n";
cin >> Option1;
checkOption(Option1);
if(Option1==1) {
cout << endl;
showRules(Option2, reshuffle, playersAces, dealersAces, naturalTest, choice1);
}
else {
shuffle1();
getInitialCards(reshuffle, playersAces, dealersAces, naturalTest, choice1);
}
}
void checkOption(int &Option1)
{
while((Option1!=1 && Option1!=2)) {
cout << "I am sorry, but you have entered a wrong option!\n";
cout << "Please press 1 to view the rules for Blackjack.\n";
cout << "Please press 2 to skip the rules and just play!\n";
cin >> Option1;
}
}
void showRules(int &Option2, int reshuffle, int playersAces, int dealersAces, int naturalTest, int choice1)
{
cout << "The rules of Blackjack are as follows:\n";
cout << "The game is played with a standard 52 card deck!\n";
cout << "The deck reshuffles after all 52 cards have been dealt!\n";
cout << "If a player is dealt a natural 21 then they automatically win!\n";
cout << "If both the player and the dealer's hands are equal, then the hand results in a push!\n";
cout << "Wins, Losses, and Ties will be counted and given to the player at the end of the game!\n";
cout << "Aces can count as either 11 or 1, and the J, Q, and K count as 10!\n";
cout << "Now, please press 1 to begin playing Blackjack!\n";
cin >> Option2;
while((Option2!=1)) {
cout << endl;
cout << "I am sorry but you did not press 1!\n";
cout << "Please press 1 to begin playing Blackjack!\n";
cin >> Option2;
}
shuffle1();
getInitialCards(reshuffle, playersAces, dealersAces, naturalTest, choice1);
}
void getInitialCards(int reshuffle, int &playersAces, int &dealersAces, int &naturalTest, int choice1)
{
int pCard1, pCard2;
int dCard1, dCard2;
int pTotal, dTotal;
int pTest = naturalTest;
if(reshuffle==52) {
cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
shuffle1();
reshuffle=0;
}
reshuffle++;
if(reshuffle==52) {
cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
shuffle1();
reshuffle=1;
}
pCard1 = cards[reshuffle];
strcpy(cardNames1[1], cardNames2[reshuffle]);
reshuffle++;
if(reshuffle==52) {
cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
shuffle1();
reshuffle=1;
}
pCard2 = cards[reshuffle];
strcpy(cardNames1[2], cardNames2[reshuffle]);
reshuffle++;
pTotal = pCard1 + pCard2;
if(reshuffle==52) {
cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
shuffle1();
reshuffle=1;
}
dCard1 = cards[reshuffle];
strcpy(cardNames1[3], cardNames2[reshuffle]);
reshuffle++;
if(reshuffle==52) {
cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
shuffle1();
reshuffle=1;
}
dCard2 = cards[reshuffle];
strcpy(cardNames1[4], cardNames2[reshuffle]);
reshuffle++;
dTotal = dCard1 + dCard2;
if(pCard1 == 1) {
playersAces = 1;
pCard1+=10;
pTotal = pCard1 + pCard2;
}
if(pCard2 == 1) {
if (pCard1 !=11) {
playersAces = 1;
pCard2+=10;
pTotal = pCard1 + pCard2;
}
else if (pCard1 = 11) {
pCard2 = 1;
pTotal = pCard1 + pCard2;
}
}
if(dCard1 == 1) {
dealersAces = 1;
dCard1+=10;
dTotal = dCard1 + dCard2;
}
if(dCard2 == 1) {
if (dCard1 !=11) {
dealersAces = 1;
dCard2+=10;
dTotal = dCard1 + dCard2;
}
else if (dCard1 = 11) {
dCard2 = 1;
dTotal = dCard1 + dCard2;
}
}
displayCardsandTotals(pTotal, dTotal);
bigProcess(naturalTest, pTotal, dTotal, playersAces, dealersAces, reshuffle, choice1);
}
| |