I am creating a blackjack game and so far I have made a card class, deck class, shoe class. The card class works, the deck class works and the shoe class works but I am still working on my GetSum() method for my hand class. I need to call the SymbolToValue method to obtain the value for each card symbol and return the sum of the cards in the hand using the cardvalues array but I am not sure on how to iterate through the _hand.
Any help would be appreciated
Here is my hand class
class Hand
{
const Int32 MAX_CARDS = 12;
private Card[] _hand = new Card[MAX_CARDS];
private Int32 _cardCount;
public Hand()
{
_cardCount = 0;
}
public Int32 CardCount
{
get
{
return _cardCount;
}
}
public void AddCard(Card card)
{
if (_cardCount < MAX_CARDS)
{
throw new Exception("Cannot of more than 12 cards in a hand");
}
else
{
_cardCount++;
card++;
}
}
public Card GetCard(Int32 cardIndex)
{
if (cardIndex >= _cardCount)
{
throw new Exception("Invalid Entry");
}
else
{
return _hand[cardIndex];
}
}
Int32[] cardValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 };
String[] cardSymbols = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
private Int32 SymbolToValue(String symbol)
{
int index = Array.IndexOf(cardSymbols, symbol);
if (index != -1)
{
return cardValues[index];
}
else
{
throw new Exception("Value Not In Table");
}
}
public Int32 GetSum()
{
String symbol;
SymbolToValue(symbol) = cardValues;
}
}