mercredi 29 avril 2015

Pick from array based on conditions C#

I'm developing a basic poker game (texas hold 'em) in C# right now. I have divided faces and suits in to Enums like so:

public enum Face { Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King }

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

I then generate a string for debug purposes to test the generation.

string[] Faces = Enum.GetNames(typeof (Face));
string[] Suits = Enum.GetNames(typeof (Suit));

int r3 = rnd.Next(Faces.Length);
int r4 = rnd.Next(Suits.Length);

string currentCard = string.Format("{0} of {1}", Faces[r3], Suits[r4]);

This will generate a random string such as "Six of Diamonds"

For the visualization of the "generated" cards, I've loaded several images of each card in a deck into the resources and loaded those images into an image array like so (shortened for clutter purposes):

Image[] cardArray = { 
                      Resources._10_of_clubs, 
                      Resources._10_of_diamonds,
                      Resources._10_of_hearts,
                      Resources._10_of_spades,
                      Resources._2_of_clubs,
                      etc...
};

Is it possible to select a specific image from the array based on the generated circumstances created by the face and suit combinations above? So if "Six of Diamonds" were to be generated, the program will go in to the array and pick out the six of diamonds resource. Sorry if this is a bit much to ask. Even a push in the right direction would be appreciated.




Aucun commentaire:

Enregistrer un commentaire