Domanda

I'm trying to make a program which makes a deck, shuffles it, and then with every button press a card is drawn and laid out.

Since my knowledge of programming is very limited, I'm really bad at planning ahead, and instead just get a general picture of what I want to end up with and then take it step by step.

My problem now is that I've ended up with a List containing my deck, like this:

        //Creates a list of cards
    protected List<Card> _cards = new List<Card>();

    public List<Card> _Cards
    {
        get { return _cards; }
        set { _cards = value; }
    }

    /// <summary>
    /// One complete deck with every face value and suit
    /// </summary>
    /// <remarks></remarks>
    public Deck()
    {
        foreach (Suit suit in System.Enum.GetValues(typeof(Suit)))
        {
            foreach (FaceValue faceVal in System.Enum.GetValues(typeof(FaceValue)))
            {
                _cards.Add(new Card(suit, faceVal));
            }
        }
    }

and then I have a ImageList containing all the images, like this:

public void LoadImages()
    {
        ImageList cardList = new ImageList();

        cardList.ImageSize = new Size(71, 96);
        // Clover
        cardList.Images.Add("c1", Properties.Resources.c1);
        cardList.Images.Add("c2", Properties.Resources.c2);
        cardList.Images.Add("c3", Properties.Resources.c3);

// Deleted some here, you get the point.

        cardList.Images.Add("sj", Properties.Resources.sj);
        cardList.Images.Add("sq", Properties.Resources.sq);
        cardList.Images.Add("sk", Properties.Resources.sk);
        cardList.Images.Add("s10", Properties.Resources.s10);
    }

The Deck List is in a Class Library, the ImageList is in a User Control Library... How could I get these two two work together?

È stato utile?

Soluzione

Create a new class which contains both items as a reference.

public class ImageCard 
{
   public Card TheCard { get; set; }
   public Image TheImage { get; set; }

}

or derive a new class from card which has a reference to an Image (or visa versa)

public class CardEx : Card
{
    public Image TheImage { get; set; }

}

Then use either one to do the processing as needed.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top