0

i am busy creating a simple blackjack game in C#.

Now for my cards i want to use an Entity Class "Kaart" because when i want to create other cardgames then Blackjack i can use this again.

So my Objects would consist of : kleur (aces,spades,..) , naam (A,K,J,10,...) and bjvalue (blackjackvalue).

I use this code for this :

    class Kaart
{
    public Kaart()
    {
    }


    public Kaart(string kleur, string naam, int bjwaarde)
    {

        this.Kleur = kleur;
        this.Naam = naam;
        this.Bjwaarde = bjwaarde;

    }
    public string Kleur { get; set; } // AutoProperty

    public string Naam { get; set; } // AutoProperty

    public int Bjwaarde { get; set; } // AutoProperty

Now my question is :

For use in my game i want to create an array which contains 52 items (0-51), all cards , which represent a full stack of cards. How should my method be to fill the array with all these objects .. i started like this :

public Kaart[] Vulstapel(Kaart[] Stapel) {

now the fastest way to add all these values to this array would be?

(the reason why i put them in an array is simple : because i want to be able to copy the array and than delete each card after its already thrown in game)

J88
  • 811
  • 7
  • 20

1 Answers1

2

I would use enums, as per: Can you loop through all enum values?

than iterate over:

public static IEnumerable<T> GetValues<T>()
{
    return Enum.GetValues(typeof(T)).Cast<T>();
}

enum Suit { Spade = 1, Heart, Diamond, Cross };

public Main()
{
    var values = GetValues<Suit>();
    foreach(var d in values)
    {
        for(int val = 2; val < 11; ++val)
        {
        Kaart k = new Kaart(val,d);
        }
    }
}
Community
  • 1
  • 1
Nicko Po
  • 727
  • 5
  • 21