[会员11200651重新提交问题]获得手持二十一点的总和 [英] [Repost of question by Member 11200651] Getting the sum of a hand blackjack

查看:90
本文介绍了[会员11200651重新提交问题]获得手持二十一点的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创造一个二十一点游戏,到目前为止,我已经制作了一个卡片类,甲板课,鞋类。卡类工作,甲板类工作和鞋类工作,但我仍然在我的手类的GetSum()方法。我需要调用SymbolToValue方法来获取每个卡片符号的值,并使用cardvalues数组返回手中卡片的总和,但我不确定如何遍历_hand。



任何帮助将不胜感激



这是我的手工课



  class  Hand 
{
const Int32 MAX_CARDS = 12 ;
私人卡[] _hand = 卡[MAX_CARDS];
private Int32 _cardCount;
public Hand()
{
_cardCount = 0 ;
}
public Int32 CardCount
{
< span class =code-keyword> get
{

return _cardCount;
}
}
public void AddCard(卡片卡)
{

if (_ cardCount < MAX_CARDS)
{
throw new 异常( 手中不能超过12张牌);
}
else
{

_cardCount ++;
card ++;

}
}
public 卡GetCard( Int32 cardIndex)
{
if (cardIndex > = _ cardCount)
{
throw new 例外( 无效条目);
}
其他
{
返回 _hand [卡片索引];
}
}
Int32 [] cardValues = { 1 2 3 4 5 6 7 8 9 10 10 10 10 };
字符串 [] cardSymbols = { A 2 3 4 5 < span class =code-string> 6, 7 8 9 10 J Q K};
private Int32 SymbolToValue( String 符号)
{
int index = Array.IndexOf(cardSymbols,symbol);
if (index!= -1)
{
return cardValues [指数];
}
其他
{
throw new 异常( 值不在表中) ;
}
}
public Int32 GetSum()
{
String 符号;
SymbolToValue(symbol)= cardValues;

}
}

解决方案

询问你的同学的解决方案:返还卡总数 [ ^ ]。

干杯

Andi

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

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;

       }
   }

解决方案

Ask your class mate's solution: Returning sum of cards[^].
Cheers
Andi


这篇关于[会员11200651重新提交问题]获得手持二十一点的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆