Click here to Skip to main content
15,501,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
>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 hand class and 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 th cardvalues array but I am not sure on how to do this

Any help would be appreciated

Heres what I have for my hand class

C#
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)
        {
            Int32 index = 0;
            if (String.Equals(cardSymbols[index], symbol))
            {
                return index;
            }
            else
            {
                throw new Exception("Value Not In Table");
            }
        }
       public Int32 GetSum()
        {
            Int32 index = 0;
            String symbol = cardSymbols[index];
           Int32 index;
            SymbolToValue(symbol); 
        }
    }
Posted
Updated 7-Dec-14 9:22am
v2
Comments
BillWoodruff 7-Dec-14 21:27pm    
Until you stop re-posting using different UserNames, I am not going to try and assist you, and I am sure other people are also not going to assist you.
Richard MacCutchan 8-Dec-14 5:31am    
In your AddCard method you should also add the value of the card to the total sum in your hand.

1 solution

You can implement your SymbolToValue method like this:
C#
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");
    }
}


For taking the sum; I cannot really help you on that because I don't know the contents of the Card class, but it probably should be easier with the SymbolToValue method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900