在C#二十一点应用程序中为卡提供值 [英] Give values to cards in C# blackjack app

查看:80
本文介绍了在C#二十一点应用程序中为卡提供值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS2010.我如何为二十一点应用程序的卡赋予价值.我知道每张卡应该获得的价值,但是,例如,我如何给红心皇后"卡赋予10?这些卡当前已加载到我项目的资源文件夹中.
我应该利用枚举吗?但是再一次,当我要检查玩家手牌的总和时,如何将这些值应用到卡上?

我不是在要求一种如何计算玩家手牌总和的方法,只是想知道如何赋予每张牌值

I am using VS2010. How would I go about giving values to cards for a blackjack app. I know the value that each card should get, but for instance, how would I give the card "Queen of Hearts" a value of 10? the cards are currently loaded into my project''s resource folder.
Should I be making use of an enum? but then once again, how do I apply those values to the card when I want to check the total sum of the players hand?

I am not asking for a method on how to calculate the total sum of the player hand, just simply want to know how to give each card value

推荐答案

类似
public enum Suit
{
    Hearts,
    Spades,
    Diamonds,
    Clubs
}





public enum Rank
{
    Ace = 1,
    //etc
    Ten,
    Jack,
    Queen,
    King
}





public class Card
{
    public Card(Suit suit, Rank rank)
    {
        Suit = suit;
        Rank = rank;
    }

    public Suit Suit
    {
        get;
        private set;
    }

    public Rank Rank
    {
        get;
        private set;
    }

    private bool IsPictureCard
    {
        get
        {
            return Rank >= Rank.Jack && Rank <= Rank.King;
        }
    }

    public int Value
    {
        get
        {
            if (IsPictureCard)
            {
                return 10;
            }
            else
            {
                return (int)Rank;
            }
        }
    }
}


使用通过代码或枚举自动分配相关值的类.
Use a class that automatically assigns the relevant value, either by code or using an Enum.


这篇关于在C#二十一点应用程序中为卡提供值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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