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
|
// Card Deck.cpp : main project file.
#include <stdio.h>
#include <ctime>
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
struct DefineCard
{
string suit;
string face;
int pointsValue; // FACE => 10 POINTS & ACE's => 1 OR 11 (WHICHEVER IS BEST FOR PLAYER/DEALER
int cardStatus; // 0 = InPlay , 1 = InDeck, 2 = DiscardPile
} Deck[53]; // Deck[52] will be used when shuffling deck
int main()
{
srand((unsigned)time(0));
int a, b;
int New_Suit = 0;
string faces[13] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
string suits[4] = { "Diamonds", "Clubs", "Hearts", "Spades" };
string Status[3] = { "In Play", "In Deck", "Discard Pile" };
int CardValue[13] = { 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
for (int x = 0; x < 52; x++)
{
Deck[x].face = faces[x % 13];
Deck[x].suit = suits[New_Suit];
Deck[x].pointsValue = CardValue[x % 13];
Deck[x].cardStatus = rand()%3;
if ((x + 1) % 13 == 0)
New_Suit++;
}
cout << "Straight deck of cards.." << endl << endl;
for (int x = 0; x < 52; x ++)
{
cout << Deck[x].face << " of " << Deck[x].suit << " : Value of " << Deck[x].pointsValue << " : " << Status[Deck[x].cardStatus] << endl;
}
for (int x = 0; x < 600; x++)
{
do{
a = rand() % 52;
b = rand() % 52;
} while (a == b);
Deck[52].face = Deck[a].face;
Deck[52].suit = Deck[a].suit;
Deck[52].pointsValue = Deck[a].pointsValue;
Deck[52].cardStatus = Deck[a].cardStatus;
Deck[a].face = Deck[b].face;
Deck[a].suit = Deck[b].suit;
Deck[a].pointsValue = Deck[b].pointsValue;
Deck[a].cardStatus = Deck[b].cardStatus;
Deck[b].face = Deck[52].face;
Deck[b].suit = Deck[52].suit;
Deck[b].pointsValue = Deck[52].pointsValue;
Deck[b].cardStatus = Deck[52].cardStatus;
}
cout << endl << "Shuffled deck of cards.." << endl << endl;
for (int x = 0; x < 52; x ++)
{
cout << Deck[x].face << " of " << Deck[x].suit << " : Value of " << Deck[x].pointsValue << " : " << Status[Deck[x].cardStatus] << endl;
}
cout << endl << endl;
cout << "Enter a number, then press 'Enter', to deal two cards each, to four players." << endl << endl;// Just to use as a pause, for now
cin >> New_Suit;
int dealt = 0, value=0;
for (int x = 0; x < 4; x++)
{
cout << "Player " << x + 1 << "'s hand.." << endl;
for (int y = 0; y < 2; y++)
{
Deck[dealt].cardStatus = 0;
cout << Deck[dealt].face << " of " << Deck[dealt].suit << " : Value is " << Deck[dealt].pointsValue << " : " << Status[Deck[dealt].cardStatus] << endl;
value += Deck[dealt].pointsValue;
dealt++;
}
cout << "Value of hand so far, equals " << value;
if (value > 21)
cout << endl << "BUSTED. Over 21";
if (value == 21)
cout << endl << "21. Automatic WIN!!";
value = 0;
cout << endl << endl;
}
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 52; y++)
{
Deck[y].cardStatus = x;
cout << Deck[y].face << " of " << Deck[y].suit << " : " << Status[Deck[y].cardStatus] << endl;
}
cout << ">>----------------------------------------------------<<" << endl;
}
}
|