コード例 #1
0
ファイル: DeckOfCards.cs プロジェクト: Rabidgeek/CIS23
        public bool Equals(DeckOfCards other)
        {
            for (int i = 0; i < CARDS; i++)
            {
                if (!cards[i].Equals(other[i]))
                {
                    return false;
                }
            }

            return true;
        }
コード例 #2
0
ファイル: CardTester.cs プロジェクト: Rabidgeek/CIS23
        public static void Main()
        {
            DeckOfCards MyDeck = new DeckOfCards();
            DeckOfCards CopyDeck = new DeckOfCards();
            Card tempCard = new DeckOfCards();
            int counter = 0;
            MyDeck.Deck();
            CopyDeck.Deck();

            // initial deck setup
            Console.WriteLine("Initial Deck setup:\n");
            for (int i = 0; i < 52; i++)
            {
                tempCard = MyDeck.GetCard(i);
                Console.Write(tempCard.ToString());

                if (i != 51)
                    Console.Write(", ");
                else
                    Console.WriteLine();

                if (i == 12 || i == 25 || i == 38)
                    Console.WriteLine();
            }

            // 20 looped shuffles
            Console.WriteLine("\nShuffle 20 times: Does this shuffle match the original deck?");
            for (int j = 0; j < 20; j++)
            {
                MyDeck.Faro();
                Console.WriteLine("\nShuffle #" + (j + 1) + ":\n");
                for (int i = 0; i < 52; i++)
                {
                    tempCard = MyDeck.GetCard(i);
                    Console.Write(tempCard.ToString());

                    if (i != 51)
                        Console.Write(", ");
                    else
                        Console.WriteLine();

                    if (i == 12 || i == 25 || i == 38)
                        Console.WriteLine();
                }

                if (MyDeck.Equals(CopyDeck))
                {
                    counter++;
                }

                // compare
                Console.WriteLine("Is this shuffle identical to the original deck? {0}", MyDeck.Equals(CopyDeck));
            }

            // print results
            Console.WriteLine("The shuffled deck has matched the original deck {0} times.", counter);
            Console.ReadKey();
        }