![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 380
Rep Power: 3
![]() |
Updating my old blackjack program
I just finished my second year of my three year programming course at college. On the break I am gonna go back and update some old programs I have done in the past to keep my skills fresh. I am gonna start with a blackjack program I did a couple years ago. I want to add inheritance to my classes, and wanted a bit of input b4 I do my overhaul. Here is the previous structure :
class Dealer
{
private:
std::vector<Card> vecShoe;
std::vector<Card> vecHand;
int total;
public:
Dealer();
std::vector<Card> GetHand();
void RecieveCard();
int GetTotal();
void ShuffleDeck();
void LoadDeck();
Card DealCard();
};
class Player
{
private:
std::vector<Card> vecHand;
int total;
int money;
public:
Player();
std::vector<Card> GetHand();
void RecieveCard(Card card);
int GetTotal();
int GetMoney();
void SetMoney(int money);
};If you need more info on the functions let me know. I want to add some inheritance. Do you guys think there is even a point to doing inheritance on this example? I guess there is a couple similar functions, but is there enough to even bother making a base class and all that stuff? Let me know what you guys would do with this to clean it up and make it better.
__________________
I am Addicted to Linux! |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 380
Rep Power: 3
![]() |
I guess if I simply wanted to add inheritance I could just go:
class Dealer
{
private:
std::vector<Card> vecShoe;
protected:
std::vector<Card> vecHand;
int total;
public:
Dealer();
virtual std::vector<Card> GetHand();
virtual void RecieveCard();
virtual int GetTotal();
void ShuffleDeck();
void LoadDeck();
void PrintDeck();
Card DealCard();
};
class Player: public Dealer
{
private:
int money;
public:
Player();
std::vector<Card> GetHand();
void RecieveCard(Card card);
int GetTotal();
int GetMoney();
void SetMoney(int money);
};
__________________
I am Addicted to Linux! |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Well, a dealer is just a player with a special set of rules.. so start there.
|
|
|
|
|
|
#4 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
I think you've got your inheritance backwards. A Dealer is a form of a Player, but a Player is not a form of a Dealer.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|