So i finished my Blackjack game project (Shuffling a deck?. It works fine, but as many of you pointed out in my first thread, it's not very well written, and the source code is also a bit too long for my liking.
So i sat down and started thinking about what i wanted to include in a Blackjack 2.0. I've now made a prototype of how my class definition for the Deck class might look, considering what you said in my previous thread.
This is how it looks, in all it's glory:
As you can see, i've decided to use a struct for my Cards, rather than an additional class, and then just integrate it into my Deck class. My plan is to save all the cards in a vector of structs, so i can use the STL functions for shuffling, rather than having to write my own again.Code:#ifndef DECK_H #define DECK_H class Deck { public: Deck(); void Shuffle(); void GetCard(std::vector &Card); private: struct Card { enum Rank { ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }; enum Suit { SPADES, CLUBS, HEARTS, DIAMONDS }; }; const unsigned int DeckSize; std::vector<Card> Deck; }; #endif
I'm not very familiar with the STL, so i have a couple of questions to begin with:
1. The above code is from a header file, should i define the Card struct as i have done, or do it in the .cpp file? (Is that even possible? Can structs have prototypes like functions?)
2. Can i declare my vector the way i did, or do i have to typedef the struct first?
3. Is there a better way of doing it, than using a struct for the Cards, and a vector for the deck?
Thanks in advance for your help![]()



LinkBack URL
About LinkBacks



