Search code examples
c#xna2d-games

How to make a card deck in XNA


I want to make a game a card game and I was thinking to make the cards as a int so I can make the game rules with if ifelse and else condition's but I don't know how to take an int and put texture and rectangle all together. So I make a research and people make the card deck from array. I'm asking what is the best way to do it and if you could give me a code example I'm a beginner in xna?

I start thinking if a way to make cards by number like int but I don't know if it gonna work like this.

int Card0 =1;
int Card1 =2;
int Card3 =3;
int Card4 =4;
int Card5 =5;
int Card6 =6;
int Card7 =7;
int Card8 =8;
int Card9 =9;
int Card10 =10;
int Card11 =11;
int Card12 =12;

///class
Passplayerturn passTurn;
UnloadCard unloadcard;

if I can do it like this I can put the rule like this.

if(Card4 >= 4)
   passTurn;
else
   unloadcard;

but I don't know how to put texture to something I made in in variable. I seen some people in Java language use Array to make deck but I don't really know how array works. I searched tutorials of array but I cant understand it.


Solution

  • If I were you I'd make a Card class

    public class Card
    {
        int number;
        int suit;  // or better yet, an enum of some sort
        Texture2d sprite;
        ...
    }
    

    and then a Deck would essentially be a collection of cards

    public class Deck
    {
        List<Card> cards;
        ...
    }