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
|
#include <iostream>
#include <ctime>
#include <iomanip>
#include <windows.h>
using namespace std;
void gotoxy(int, int);
char suit(int);
int value(int);
char picture(int);
void calc_tot(int[], int, int);
void Deal_Two_Cards(int[], int[]);
void DealToPlayers(int[], int[]);
int main()
{
int cards[52], picked[52] = { 0 }, i, Tot[8] = { 0 }, j;
int moreCards[7] = { 1 };
char hitStand = ' ';
srand(time(NULL));
for (i = 0; i < 52; i++)
{
do
{
cards[i] = rand() % 52;
} while (picked[cards[i]] != 0);
picked[cards[i]] = 1;
cout << cards[i] << endl;
}
Deal_Two_Cards(cards, Tot);
j = 15;
// loop with a call to a function to deal cards to a player
for (int i = 0; i < 7; i++) {
gotoxy(0, 17);
cout << "Would Player " << i + 1 << " like another card? (Please enter 'y' or 'n' ";
cin >> hitStand;
while (hitStand != 'y' && hitStand != 'n') {
cout << "That is not a valid choice. Please enter 'y' or 'n'. ";
cin >> hitStand;
}
if (hitStand == 'y') {
moreCards[i] = 1;
}
else if(hitStand == 'n') {
moreCards[i] = 0;
}
while (moreCards[i] == 1) {
DealToPlayers(cards, Tot);
}
}
// call a function to finish the dealer
// call a function to determine win/lose/tie
system("pause");
return 0;
}
void gotoxy(int h, int w)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (INVALID_HANDLE_VALUE != hConsole)
{
COORD pos = { h, w };
SetConsoleCursorPosition(hConsole, pos);
}
return;
}
char suit(int i)
{
char c;
c = char(i / 13 + 3);
return c;
}
int value(int i)
{
int r;
if (i % 13 == 0)
r = 1;
else if (i % 13 > 9)
r = 10;
else
r = i % 13 + 1;
return r;
}
char picture(int i)
{
char c = ' ';
if (i % 13 == 0)
c = 'A';
else if (i % 13 == 10)
c = 'J';
else if (i % 13 == 11)
c = 'Q';
else if (i % 13 == 12)
c = 'K';
return c;
}
void calc_tot(int T[], int v, int p)
{
T[p] = T[p] + v;
return;
}
void Deal_Two_Cards(int cards[], int Tot[])
{
int i, row = 1, v, k = 1;
char c, s;
cout << right;
system("cls");
cout << setw(8) << "Dealer" << setw(8) << "P1" << setw(8) << "P2" << setw(8) <<
"P3" << setw(8) << "P4" << setw(8) << "P5" << setw(8) << "P6" << setw(8) << "P7" <<
endl;
gotoxy(0, row);
cout << setw(8) << "???";
for (i = 0; i < 15; i++)
{
if (i == 7)
row++;
s = suit(cards[i]);
v = value(cards[i]);
c = picture(cards[i]);
gotoxy(k % 8 * 8, row);
if (c != ' ')
cout << setw(7) << c << s;
else
cout << setw(7) << v << s;
calc_tot(Tot, v, k % 8);
gotoxy(k % 8 * 8, 17);
cout << setw(8) << "Total";
gotoxy(k % 8 * 8, 18);
cout << setw(8) << Tot[k % 8];
k++;
}
}
void DealToPlayers(int cards[], int Tot[]) {
return;
}
|