Hello all - I have a small card game project due this Sunday that involves creating 2 separate classes: one for card objects(myCard), one for a deck object (myDeck) that creates 60 cards in its constructor. However, if I just call 60 card objects in the deck's constructor through inheritance and create a deck object in main, I don't believe I would be able to manipulate/access those individual card objects due to scope(? - could be wrong).
If I, for example, wanted to shuffle the deck and manipulate those individual cards, what would be the best way to structure this? Should I create a vector of "myCard" objects as a protected variable, use push_back for 60 cards in the myDeck's constructor and access them that way?
My apologies if this is a weird question. I am still very new to the language while going to school for business, so finding the most logical way to approach smaller projects seems to be a struggle for me at the moment.
// Regular deck of 52 cards
constint Ranks = 13, Suits = 4, DeckSize = Ranks * Suits;
class Card {
int rank, suit;
public:
Card(int r, int s) : rank(r), suit(s) { }
int getRank() const { return rank; }
int getSuit() const { return suit; }
};
class Deck {
std::vector<Card> cards;
int top; // may need this for dealing
// (unless you are popping cards from the vector)
public:
Deck() : top(0) {
for (int s = 0; s < 4; s++)
for (int r = 1; r <= 13; r++)
cards.push_back(Card(r, s));
}
void shuffle() { } // you can shuffle the cards here
}