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
|
#ifndef card_h
#define card_h
// I define some enums here in order to help represent
// certain attributes of the cards. Such as Rank and Suit.
//
// I also create some string arrays to help represent each item
// contained within the enums
enum Suit {
hearts, spades, diamonds, clubs
};
std::string suit[] = {
"hearts", "spades", "diamonds", "clubs"
};
enum Rank {
ace, two, three, four, five, six, seven,
eight, nine, ten, jack, queen, king
};
std::string rank[] = {
"ace", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "jack",
"queen", "king"
};
// Constant variables to represent the amount
// of ranks and suits
const int maxRank = 13;
const int maxSuit = 4;
// This class will be used to create a card
class Card{
public:
Card();
Card(const int &suit, const int &rank);
private:
int getSuit() const;
std::string getSuitName() const;
int getRank() const;
std::string getRankName() const;
int generateSuit();
int generateRank();
int m_rank;
int m_suit;
// Deck will need to be able to access attributes of the card,
// but the card will not need to access deck at all
friend class Deck;
};
// Default constructor generates a random card
Card::Card(){
m_suit = generateSuit();
m_rank = generateRank();
}
// Generates a card based on values given through for...loop in deck.h
Card::Card(const int &suit, const int &rank): m_suit(suit), m_rank(rank){};
// Get the value of m_rank
int Card::getRank() const{
return m_rank;
}
// Get the value of m_suit
int Card::getSuit() const{
return m_suit;
}
std::string Card::getRankName() const{
return rank[getRank()];
}
std::string Card::getSuitName() const{
return suit[getSuit()];
}
// Generate a value for m_rank
int Card::generateRank(){
return rand() % maxRank;
}
// Generate a value for m_suit
int Card::generateSuit(){
return rand() % maxSuit;
}
#endif /* card_h */
|