I have a Deck class that instantiates your standard 52-card deck. I'm making a Durak card game, which allows you to use different sized decks. So I'm inheriting Deck, with a new DurakDeck class.
I have the following DurakDeck constructor (I also have a default constructor, that more or less does something similar). I'm running into an issue, where it looks like when I instantiate a DurakDeck, it is also calling the Deck constructor, because my DurakDeck object ends up containing however many cards it was told to instantiate in it's constructor, plus an extra 52-cards (coming from Deck).
Does the parent class constructor call automatically? I always assumed it only called if you had the : base()
specified...?
Not really sure where I am going wrong...
public DurakDeck(byte deckSize)
{
const Rank SMALL_DECK_START = Rank.Ten;
const Rank NORMAL_DECK_START = Rank.Six;
const Rank LARGE_DECK_START = Rank.Deuce;
this.deckSize = (deckSize - 1);
Rank startingValue = Rank.Six;
// Check what deckSize is equal to, and start building the deck at the required card rank.
if (deckSize == SMALL_SIZE) { startingValue = SMALL_DECK_START; }
else if (deckSize == NORMAL_SIZE) { startingValue = NORMAL_DECK_START; }
else if (deckSize == LARGE_SIZE) { startingValue = LARGE_DECK_START; }
else { startingValue = NORMAL_DECK_START; }
// Ace is 1 in enum, and Durak deck can initialize at different sizes,
// so we add the aces of each 4 suits first.
for (int suitVal = 0; suitVal < 4; suitVal++)
{
cards.Add(new Card((Suit)suitVal, Rank.Ace));
}
// Loop through every suit
for (int suitVal = 0; suitVal < 4; suitVal++)
{
// Loop through every rank starting at the starting value determined from the if logic up above.
for (Rank rankVal = startingValue; rankVal <= Rank.King; rankVal++)
{
// Add card to deck
cards.Add(new Card((Suit)suitVal, rankVal));
}
}
}