I am trying to deal 5 cards to a Hand object that can contain 6 card objects. Ive written the hand class, the deck class and the card class.
The code deals cards to the Hand object which can contain Card objects, but i keep on getting the System.Reflection.TargetInvocationException in Presentation.dll exception.
//function to deal specified player the topmost cards from deck
//recieves an array of hands or Hand object
public void dealPlayerCardsFromDeck(Hand players, int numberOfCards )
{
int j = 0;
//loop to go through deck elements and to ensure the end of the player's hand isnt reached
for (int i = 0; (i < deckLength) && (j <= numberOfCards); i++)
{
if (deck[i] != null)
{
players.hands[j].face = deck[i].face;
players.hands[j].value = deck[i].value;
deck[i] = null;
j++;
}
}
}//end function
Here is the code that calls it in Main()
cardDeck.dealPlayerCardsFromDeck(players[0],5);
the "cardDeck" is an object of Class Deck
Deck cardDeck = new Deck();
Please note I am using c#