Hey everyone, I currently am creating a Card shuffling program in C++, Ive taken care of the shuffling of the deck. Now I just need to distribute a hand of 5 cards, and determine hands. Can anyone help? Please!
cardheader.h ( includes both Class Card & Deck )
#ifndef CARDHEADER_H
#define CARDHEADER_H
#include <vector>
enum Face{ Ace , Two , Three , Four , Five , Six , Seven , Eight , Nine, Ten , Jack , Queen , King };
enum Suit{ Diamonds , Hearts , Clubs , Spades };
class Card{
public:
Card( Face, Suit );
void get_cardvalues( Face & , Suit & );
private:
Face myFace;
Suit mySuit;
};
class Deck{
public:
Deck( void );
~Deck();
void shuffle_cards( bool swap = false );
void print_tostring();
private:
std::vector<Card> deck;
};
#endif
cardndeck.cc ( includes card & deck implementations )
#include <algorithm>
#include <iostream>
#include <ctime>
#include "cardheader.h"
using namespace std;
Card::Card( Face face, Suit suit ){
myFace = face;
mySuit = suit;
}
void Card::get_cardvalues( Face &face, Suit &suit ){
face = myFace;
suit = mySuit;
}
Deck::Deck(){
int counter = 0;
int i;
int j;
for( j = int( Ace ); j <= int( King ); j++ ){
for( i = int( Diamonds ); i <= int( Spades ); i++ ){
deck.push_back( Card( Face( i ) , Suit( j ) ) );
counter++;
}
}
}
Deck::~Deck(){
deck.clear();
}
void Deck::print_tostring(){
int i;
static const char *faces[] = { "Diamonds" , "Hearts" , "Clubs" , "Spades" };
static const char *suits[] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
for( i = 0; i < ( int )deck.size(); i++ ){
Face f_temp;
Suit s_temp;
deck[ i ].get_cardvalues( f_temp , s_temp );
cout << "[" << suits[ s_temp ] << " of " << faces[ f_temp ] << "]";
cout << endl;
}
cout << endl;
}
void Deck::shuffle_cards( bool swap ){
static bool swapper;
if( !swapper && swap ){
srand( unsigned( time( NULL )));
swapper = true;
}
random_shuffle( deck.begin() , deck.end() );
}