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
|
#include "cards.h"
//Card array
cards hand[52];
//Constants
const int PLAYERCOUNT = 7;
const int GAMELIMIT = 21;
const int DEALER = 16;
const int TWOCARD = 2;
//Functions
void Dealer(string dName[], int dHit[], int i)
{
i = PLAYERCOUNT;
dName[i+1] = "Dealer";
dHit[i+1] = DEALER;
}
void display()
{
cout << "BlackJack by Jordan Lillie" << endl;
cout << "The shuffled deck is : " << endl;
for(int i = 0; i < 52; i++)
{
if(i % 13 == 0)
{
cout << endl;
}
hand[i].display();
cout <<' ' << ' ';
}
cout << '\n' << endl;
}
void displayHit(string playersName[], int hitLim[])
{
cout << "Player Name" << '\t' << "Hit Limit" << endl;
for(int i = 0; i < PLAYERCOUNT-1; i++)
{
setfill(" ");
cout << right << setw(11) << playersName[i] << " "
<< right << setw(9) << hitLim[i] << endl;
}
cout << endl;
}
void deal(string playersName[],int playerStat[])
{
int counter = 0;
cout << "Deal two cards to everyone" << endl;
for(int i = 0; i < TWOCARD; i++)
{
for( int j = 0; j < PLAYERCOUNT; j++)
{
playerStat[j] += hand[counter++].getFace();
}
}
//Display
for( int k = 0; k < PLAYERCOUNT; k++)
{
cout << "Hand for " << playersName[k] << " is : " ;
hand[k].display();
cout << " and " ;
hand[k + PLAYERCOUNT].display();
cout << " Value for this hand is " << playerStat[k] << endl;
}
cout << endl << endl;
}
void limits(string playersName[], int playersStat[], int hitLim[])
{
int hitCount = PLAYERCOUNT * TWOCARD;
int k = 0;
for( k = 0; k < PLAYERCOUNT; k++)
{
while(playersStat[k] < hitLim[k])
{
playersStat[k] += hand[hitCount].getFace();
cout << "Player " << playersName[k] << " getting another card ";
hand[hitCount].display();
cout << endl;
hitCount++;
}
cout << "Value of hand for " << playersName[k] << " is now " << playersStat[k] << endl;
}
}
void displayEndgame(int playerStat[], string playersName[])
{
cout << endl;
cout << "Results of this game" << endl;
for(int i = 0; i < PLAYERCOUNT - 1; i++)
{
if(playerStat[PLAYERCOUNT-1] == GAMELIMIT)
{
for( int k = 0; k < PLAYERCOUNT - 1; k++)
{
cout << "The deal beats player" << playersName[k] << endl;
}
break;
}
if(playerStat[i] > GAMELIMIT)
{
cout << "Dealer beats player " << playersName[i] << endl;
}
else
{
if(playerStat[PLAYERCOUNT-1] <= GAMELIMIT)
{
if(playerStat[PLAYERCOUNT - 1] >= playerStat[i])
{
cout << "Dealer beats player" << playersName[i] << endl;
}
else
{
cout << "Player " << playersName[i] << " beats the dealer" << endl;
}
}
else
{
cout << "Player " << playersName[i] << " beats the dealer" << endl;
}
}
}
cout << endl;
}
void game(string playersName[],int hitLim[],int i,
int playerStat[])
{
Dealer(playersName,hitLim,i);
display();
displayHit(playersName, hitLim);
deal(playersName, playerStat);
limits(playersName, playerStat, hitLim);
displayEndgame(playerStat, playersName);
}
void shuffleCards(int counter)
{
for(int s = 3; s <= 6; s++)
{
for (int f = 1; f <= 13; f++)
{
hand[counter] = cards(f, char (s));
counter++;
}
}
for(int i = 0; i < 52; i++)
{
hand[i].swap(hand[(rand() % 52)]);
}
cout << endl;
}
|