Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Something like
C#
public enum Suit
{
    Hearts,
    Spades,
    Diamonds,
    Clubs
}


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


C#
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;
            }
        }
    }
}
 
Share this answer
 
Comments
Andrew797 11-Nov-11 8:19am    
thanks for the post. I am totally new to this, what I don't understand is, when the card image is loaded into the picturebox, how will I know the value of that card based on the enums above? sorry if this question is irrelevant, but I still dont know how to link the values of the enum to the actual card image?
Richard MacCutchan 11-Nov-11 9:05am    
I think perhaps you need to take a step back and learn about classes and methods before attempting this project.
RaviRanjanKr 11-Nov-11 15:40pm    
My 5+
Use a class that automatically assigns the relevant value, either by code or using an Enum.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900