lundi 20 juillet 2015

C# assigning value to array

I'm trying to write a program that would shuffle 13 playing cards from ace to king. Deal 2 cards out and add up the value that's assigned to each card. ace = 11, king = 10, jack = 10, queen = 10, ten = 10, nine = 9, eight = 8 and so on... sort of like blackjack.

so far I'm only able to shuffle the cards and print out two cards randomly but i don't know how to assign a value to each card, add them up and print it out. example, if my two random cards is King and Eight then i would want the program to print out..

King

Eight

18

here's what i got...

        static void Main(string[] args)
    {
        string[] Cards = new string[] {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "jack", "Queen", "King", "Ace"};

        for (int x = 0; x < 100; x++) // looping the shuffle 100 times to maximize the randomness
        {
            for (int i = Cards.Length; i > 0; i--) //shuffle
            {
                string temp;
                Random random = new Random();
                int r = random.Next(i);
                temp = Cards[r];
                Cards[r] = Cards[i-1];
                Cards[i-1] = temp;
            }  
        }
        Console.WriteLine(Cards[0]); //first random card
        Console.WriteLine(Cards[1]); //second random card
        Console.ReadKey();
    }




Aucun commentaire:

Enregistrer un commentaire