如何计算卡片的分数值 [英] How to calculate a score value for cards

查看:101
本文介绍了如何计算卡片的分数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在计算每张卡的得分值。



到目前为止我所拥有的是球员,经销商和卡类。 Iv创建了一个计算类来处理所有的计算,并将每张卡的分数交给经销商或玩家类。



我的理论是发送每张卡被分发到计算类,然后检查它是什么卡,然后将该特定卡的值发送到玩家类,以增加玩家得分的卡数。



但是现在我如何检查卡片并给它一个分数?



我喜欢这个但它太乱了



 开关(newCard)
{
case Spades2:
case Hearts2:
案例 钻石2:
case Clubs2:
pScore = 2 ;
break ;

}



等等。

newCard =卡片值进来且pScore =球员得分。< br $> b $ b

抬头:我还是个君子,所以请不要抨击我。

提前致谢。







编辑:

这是我的其余代码,因为你们可以看到我到目前为止所拥有的内容。

我知道很多代码,但请耐心等待。



卡类:

  public   static   class 
{
私人 静态 string [] Suite = new string [ 4 ] { 分会 Hearts 黑桃 钻石};
private static string [ ] FaceValue = new string [ 13 ] { Ace 2 3 4 5 6 7 8 9 10 Jack Queen King};


public static 列表< string> CreateDeck()
{
List< string> deckOfCards = new List< string>();

for int s = 0 ; s < 4 ; s ++)
{
string sut = Suite [s];

for int fV = 0 ; fV < 13 ; fV ++)
{
string value = FaceValue [fV];

deckOfCards.Add(sut + value );
}
}
// For循环结束。
deckOfCards.Shuffle();

return deckOfCards;
}

public static 无效随机播放< T>( IList< T>列表)
{
随机rng = new Random();
int n = list.Count;
while (n > 1
{
n--;
int k = rng.Next(n + 1 );
T value = list [k];
list [k] = list [n];
list [n] = value ;
}
}
}



我知道我应该使用enume而不是数组。





经销商类:

<前lang =c#> 经销商
{
私人列表< string> randomisedCards;

public 经销商()
{
randomisedCards = Card.CreateDeck();
}


public string dealCard()
{
string randCard = randomisedCards [ 0 ];
randomisedCards.RemoveAt( 0 );

return randCard;
}
}



我想将ranCard发送到calculate类来计算该卡的分数值。





计算类:

<前lang =c#> 计算
{
// 成员变量。
< span class =code-keyword> private string newCard;
private int pScore;
private int dScore;


// 重载的构造函数。
< span class =code-keyword> public 计算(字符串卡)
{
newCard = card;
}

public 计算( int playerScore, int dealerScore)
{
pScore = playerScore;
dScore = dealerScore;
}

public void calculateScore()
{
switch (newCard)
{
case 黑桃
case Hearts
pScore = 11 ;
break ;

// 等。
}
}
}





我在第一个构造函数中接收随机卡,在第二个构造函数中接收玩家得分,这样我就可以发送卡值对玩家类别。





玩家类

 < span class =code-keyword> class 播放器
{
// 成员变量。
private int newPlayerScore;
private int newPlayerWin;
private int newPlayerLosses;
private int newPlayerTies;

// 用于将成员变量设置为默认值并将使用的Defalut构造函数重置
// 玩家详情。
public Player()
{
newPlayerScore = 0 ;
newPlayerWin = 0 ;
newPlayerLosses = 0 ;
newPlayerTies = 0 ;
}

// 用于获取和设置玩家得分的属性。
public int calcPlayerScore
{
获取
{
return newPlayerScore;
}
set
{
newPlayerScore + = value ;
}
}

}





计算玩家得分属性将积累球员得分。

解决方案

我们不能准确,因为我们不知道你的系统的其余部分是什么样的。但是......我这样做的方法是创建一个包含两个值的Card类:

  public   enum 套装
{
Diamond,Spade,Club,Heart
}
公开 枚举面对
{
一个= 1
Ace = 1
两个,
三个,
...
King
}
public class
{
public Suit Suit { get ; set ; }
public Face Face { get ; set ; }
}



并添加一个生成得分值的属性(如果它已修复且与手中的其他卡无关)

如果它是相关的,我可能会生成一个包含Card对象集合的Hand类,并且具有Score属性。



那样,如果Face是Two,那么score是(int)Face 等等。

  public   int 得分
{
get { return int )Face; }
}


如何创建Card类并在构造函数中实例化每个卡,赋予它具体的价值,将其添加到卡片组(卡片集合) )然后简单地向玩家发送具体的卡片 - 轻松计算得分吧



等级卡

公共财产颜色

公共财产价值

公共财产PointValue

终结类



公共enum cardcolor

黑桃

红色

钻石

俱乐部

结束枚举



您可以为卡片值执行类似的枚举,这样您就可以获得cardValue.Jack或cardValue.Ace而不是数字


Hi there all,
I am trying to calculate the score value for each card.

What I have so far is a player, dealer and card class. Iv created a calculate class as to handle all the calculations and hand the score for each card back to the dealer or player class.

My theory is to send each card that is handed out to the calculate class, then check what card it is and then send the value for that specific card to the player class to increment the players score by the cards amount.

But now how do I check the card and give it a score ?

I hade this but its to messy

switch (newCard)
{
    case "Spades2:"
    case "Hearts2:"
    case "Diamonds2:" 
    case "Clubs2:"
        pScore = 2;
        break;
  
}


And so on.
newCard = the card value coming in and pScore = player score.

Heads up : im still a junier so please no bashing me.
Thanks in advance.



EDIT :
This is the rest of my code as you guys can see what I have so far.
I know its a lot of code but please bear with me.

Card Class :

public static class Card
    {
        private static string[] Suite = new string[4] {"Clubs", "Hearts", "Spades", "Diamonds" };
        private static string[] FaceValue = new string[13] {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };


        public static List<string> CreateDeck()
        {
            List<string> deckOfCards = new List<string>();

            for (int s = 0; s < 4; s++ )
            {
                string sut = Suite[s];

                for (int fV = 0; fV < 13; fV++)
                {
                    string value = FaceValue[fV];

                    deckOfCards.Add(sut + value);
                }
            }
            // End of For loop.
            deckOfCards.Shuffle();

            return deckOfCards;
        }

        public static void Shuffle<T>(this IList<T> list)
        {
            Random rng = new Random();
            int n = list.Count;
            while (n > 1)
            {
                n--;
                int k = rng.Next(n + 1);
                T value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
    }


I know that I should have used enume instead of an array.


Dealer Class :

class Dealer
    {
        private List<string> randomisedCards;

        public Dealer()
        {
            randomisedCards = Card.CreateDeck();
        }


        public string dealCard()
        {
            string randCard = randomisedCards[0];
            randomisedCards.RemoveAt(0);

            return randCard;
        }
    }


I wanted to send the ranCard to the calculate class to calculate the score value for that card.


Calculate class :

class Calculate
    {
        // Member variable.
        private string newCard;
        private int pScore;
        private int dScore;


        // Overloaded constructor.
        public Calculate(string card)
        {
            newCard = card;
        }

        public Calculate(int playerScore, int dealerScore)
        {
            pScore = playerScore;
            dScore = dealerScore;
        }

        public void calculateScore()
        {
            switch (newCard)
            {
                case "Spades":
                case "Hearts":
                    pScore = 11;
                    break;

                    // etc.
            }
        }
    }



Im receiving the random card in the first constructor and the player score in the second constructor so I can send the cards value to the player class.


Player class

class Player
    {
        // Member variables.
        private int newPlayerScore;
        private int newPlayerWin;
        private int newPlayerLosses;
        private int newPlayerTies;

        // Defalut constructor used to set the member variables to their default values and will be used to reset
        // the players details.
        public Player()
        {
            newPlayerScore = 0;
            newPlayerWin = 0;
            newPlayerLosses = 0;
            newPlayerTies = 0;
        }

        // Propertie used to get and set the players score.
        public int calcPlayerScore
        {
            get
            {
                return newPlayerScore;
            }
            set
            {
                newPlayerScore += value;
            }
        }

    }



The calculate player score propertie will accumulate the players score.

解决方案

We can't be precise, because we have no idea what teh rest of your system looks like. But...the way I would do it is to create a Card class which contained two values:

public enum Suit
   {
   Diamond, Spade, Club, Heart
   }
public enum Face
   {
   One = 1,
   Ace = 1,
   Two,
   Three,
   ...
   King
   }
public class Card
   {
   public Suit Suit { get; set; }
   public Face Face { get; set; }
   }


And add a property which generated a "score" value (if it's fixed and not related to the other cards in the hand)
If it is related, I'd probably generate a Hand class which contained a collection of Card objects, and had the Score property.

That way, if the Face is "Two", then the "score" is (int) Face and so forth.

public int Score
   {
   get { return (int) Face; }
   }


How about creating Card class and instantiating each card in the constructor giving it concrete value, adding it to the deck (collection of cards) and then simply sending concrete cards to players - easily calculating the score from that

Class Card
Public property Color
public property Value
public property PointValue
end class

public enum cardcolor
Spades
Hearts
Diamonds
Clubs
end enum

you can do similar enum for card values so you get cardValue.Jack or cardValue.Ace instead of numbers


这篇关于如何计算卡片的分数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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