我正在尝试将 5 张牌发给可以包含 6 张牌对象的手对象。我写了手牌类、套牌类和卡片类。
该代码将卡片处理给可以包含卡片对象的 Hand 对象,但我继续在 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" 是 Class Deck 的一个对象
Deck cardDeck = new Deck();
请注意我使用的是 c#