samedi 1 octobre 2016

C# pick per random out of an enum, but cupple it with if

So I have to programm Black Jack as a console programm in C#. I added an enum with all the cards in it (without colors. just numbers, ace and picure card) and give them values. then i made a method to return a random card. this works fine. but in the second step of the task i have to ad the picture cards and i have to take care of the count of picture cards in the deck. the deck is 52 cards large and 12 of them are picture cards. i tried the following but it wont work.

class Program
{
    static Random rnd = new Random(); //initialisierung Zufallsgenerator
    static ECARDS DrawRandomCard() //Methode zum zufälligen ziehen einer karte aus dem enum ECARDS
    {
        if ((int)DrawRandomCard() < 12)
        {
            return ECARDS.Picture;
        }
        else
        {
            return (ECARDS)rnd.Next(2, 11);
        }            
    }



    enum ECARDS { Zwei = 2, Drei = 3, Vier = 4, Fünf = 5, Sechs = 6, Sieben = 7, Acht = 8, Neun = 9, Zehn = 10, Ass = 11, Picture = 99 }; // enum mit allen verfügbaren karten

im a newbie so maybe its very easy for you. thanks for your help. (and sorry if my english isnt the best ;)




Aucun commentaire:

Enregistrer un commentaire