Click here to Skip to main content
15,899,679 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 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

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)
       {
           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;

       }
   }
Posted
Updated 7-Dec-14 15:25pm
v2

1 solution

Ask your class mate's solution: Returning sum of cards[^].
Cheers
Andi
 
Share this answer
 
v2
Comments
BillWoodruff 7-Dec-14 21:22pm    
Hi Andreas, This is another in a series of re-posts by someone using three separate UserNames on CP. The right thing to do when you see a re-post is to report it using the 'Repost option under the "red-flag" drop-down menu.

It's too bad really: the person posting these messages has had lots of excellent responses to their various questions, but shows almost no sign of having benefited from any of them.

Posting this kind of message is not a "solution," and just clutters up the Forum.

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