示例#1
0
        static void Main(string[] args)
        {
            int cardCount = 0;
            int cardMaxCount = 50;

            Deck myDeck = new Deck();
            myDeck.Shuffle();

            Card[] myCardArray = new Card[5];

            int flagcounter = 0;

            while (cardCount < cardMaxCount)
            {

                flagcounter = 0;

                for (int j = 0; j < 5; j++)
                {

                    myCardArray[j] = myDeck.GetCard(cardCount);

                    if (myCardArray[j].suit != myCardArray[0].suit)
                    {

                        flagcounter += 1;

                    }

                    cardCount += 1;

                }

            }

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(myCardArray[i].ToString());
            }

            if (flagcounter == 0)
            {

                Console.WriteLine("Flush!");

            }
            else
            {

                Console.WriteLine("No Flush!  Too Bad.");

            }

            Console.ReadKey();
        }
示例#2
0
文件: Deck.cs 项目: ktjones/BVCS2012
        public Deck()
        {
            cards = new Card[52];

            for (int suitVal = 0; suitVal < 4; suitVal++)
            {
                for (int rankVal = 1; rankVal < 14; rankVal++)
                {
                    cards[suitVal * 13 + rankVal - 1] = new Card((Suit)suitVal,(Rank)rankVal);
                }
            }
        }
示例#3
0
文件: Deck.cs 项目: ktjones/BVCS2012
        public void Shuffle()
        {
            Card[] newDeck = new Card[52];
            bool[] assigned = new bool[52];
            Random sourceGen = new Random();

            for (int i = 0; i < 52; i++)
            {
                int destCard = 0;
                bool foundCard = false;
                while (foundCard == false)
                {
                    destCard = sourceGen.Next(52);
                    if (assigned[destCard] == false)
                        foundCard = true;
                }
                assigned[destCard] = true;
                newDeck[destCard] = cards[i];
            }

            newDeck.CopyTo(cards, 0);
        }