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
|
// Blackjack03
#include <iostream>
#include <cstdlib>
#include <ctime>
#define DECKS 6 //number of decks in dealing shoe
class Card
{
int m_rank;
char m_name;
char m_suit;
public:
void setcard(int rank, char suit);
void showcard();
};
void Card::setcard(int rank, char suit){
char names[]{ 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
m_suit = suit;
m_rank = rank;
m_name = names[rank-1];
}
void Card::showcard(){
std::cout << m_name << m_suit;
}
class Shoe
{
Card * m_cards;
int m_numdecks;
int cardsdelt = 0;
public:
Shoe(int numdecks)
{
m_numdecks = numdecks;
m_cards = new Card[numdecks * 52];
}
virtual ~Shoe()
{
delete[] m_cards;
}
void initialize();
void shuffle();
void display();
void deal(int numplayers);
};
void Shoe::initialize(){
int shoeindice = 0;
char suit[]{'H', 'D', 'C', 'S'};
for (int deck = 0; deck < m_numdecks; deck++)
for (int rank = 1; rank < 14; rank++)
for (int s = 0; s< 4; s++)
m_cards[shoeindice++].setcard(rank, suit[s]);
}
void Shoe::shuffle(){
Card temp;
int card1, card2;
int size = 52 * m_numdecks;
for (int i = 0; i < 400; i++){
card1 = (rand() % size);
card2 = (rand() % size);
temp = m_cards[card1];
m_cards[card1] = m_cards[card2];
m_cards[card2] = temp;
}
}
void Shoe::display(){
int shoeindice = 0;
for (int deck = 0; deck < m_numdecks; deck++){
for (int i = 0; i < 26; i++){
m_cards[shoeindice++].showcard();
std::cout << " ";
}
std::cout << '\n';
for (int i = 0; i < 26; i++){
m_cards[shoeindice++].showcard();
std::cout << " ";
}
std::cout << '\n';
}
std::cout << '\n';
}
void Shoe::deal(int numplayers){
/* This will probably take a Player class array
not an int.
*/
}
int main(){
Shoe myshoe(DECKS);
srand((unsigned)time(0));
myshoe.initialize();
myshoe.display();
myshoe.shuffle();
myshoe.display();
myshoe.initialize();
myshoe.shuffle();
myshoe.display();
return 0;
}
|