0
我正在试图将5张牌交给一个可以包含6张牌对象的手形物体。 我写过手课,甲板课和卡课。将牌从一副牌交给一张名为Hands的牌阵列
该代码将卡交易给Hand对象,该对象可以包含Card对象,但我一直在Presentation.dll异常中获取System.Reflection.TargetInvocationException。
//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
这里是调用它在main(代码)
cardDeck.dealPlayerCardsFromDeck(players[0],5);
的 “cardDeck” 是类甲板的对象
Deck cardDeck = new Deck();
请注意我使用C#
我确实这样做,异常发生在“players.hands [j] .face = deck [i]”。面对;”在我或j得到增加之前 –