I initialize the lookups in the overidden virtual function initialize declared in the base class.
Code:
class Hand : public Data
{
void draw(Card card)
{
hand.push_back(card);
}
std::vector<Card> get_cards()
{
return hand;
}
string read_cards()
{
show_hand.erase();
for(unsigned int loop = 0; loop < hand.size(); loop++)
{
std::cout << hand[loop].Value << std::endl;
std::cout << values[hand[loop].Value].c_str() << std::endl;
show_hand.append(values[hand[loop].Value]);
show_hand.append(" of ");
show_hand.append(suits[hand[loop].Suit]);
show_hand.append(" ");
}
show_hand.append("\n");
return show_hand;
}
void initialize()
{
add_to_lookup(suits, "Clubs");
add_to_lookup(suits, "Diamonds");
add_to_lookup(suits, "Hearts");
add_to_lookup(suits, "Spades");
add_to_lookup(values, "Two");
add_to_lookup(values, "Three");
add_to_lookup(values, "Four");
add_to_lookup(values, "Five");
add_to_lookup(values, "Six");
add_to_lookup(values, "Seven");
add_to_lookup(values, "Eight");
add_to_lookup(values, "Nine");
add_to_lookup(values, "Ten");
add_to_lookup(values, "Jack");
add_to_lookup(values, "Queen");
add_to_lookup(values, "King");
add_to_lookup(values, "Ace");
}
private: // lookups
friend class Dealer;
friend class Game;
lookup suits;
lookup values;
string show_hand;
vector<Card> hand;
};
The base class:
Code:
class Data // this is the class that will define how we output certain data sets on the screen
{
public:
typedef std::vector<string> lookup;
// everytime we create a class that is derived from Data it will run this function
Data()
{
initialize();
}
void add_to_lookup(lookup table, string word)
{
table.push_back(word);
}
virtual void initialize(){}// function to initialize a specific lookup.
virtual void read_data(){} // function to output specific data.
};