返还卡的总和 [英] Returning sum of cards
问题描述
>我正在创造一个二十一点游戏,到目前为止,我已经制作了一个卡片类,甲板课,鞋类。卡类工作甲板类工作和鞋类工作,但我仍然在我的手类上工作,我需要调用SymbolToValue方法获取每个卡符号的值,并使用th返回手中的卡的总和cardvalues数组,但我不知道如何做这个
任何帮助将不胜感激
Heres我手上课的内容
>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
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);
}
}
推荐答案
您可以像这样实现SymbolToValue方法:
You can implement your SymbolToValue method like this:
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");
}
}
取得金额;我无法真正帮助你,因为我不知道Card类的内容,但使用SymbolToValue方法可能会更容易。
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.
这篇关于返还卡的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!