改進一次取出五張牌判斷花色是否相同的代碼

static void Main(string[] args)
        {
            string str = "y";
            while (str=="y"||str=="Y")
            {
                Deck playDeck = new Deck();
                playDeck.Shuffle();
                bool isFlush = false;
                int flushHandIndex = 0;
                int hand = 0;
                for (hand = 0; hand < 10; hand++)
                {
                    isFlush = true;
                    Suit flushSuit = playDeck.GetCard(hand * 5).suit;
                    for (int card = 1; card < 5; card++)
                    {
                        if (playDeck.GetCard(hand * 5 + card).suit != flushSuit)
                        {
                            isFlush = false;
                            break;
                        }
                    }
                    if (isFlush)
                    {
                        flushHandIndex = hand * 5;
                        break;
                    }
                }
                if (isFlush)
                {
                    WriteLine($"Flush! 取牌{++hand}次後成功!");
                    for (int card = 0; card < 5; card++)
                    {
                        WriteLine(playDeck.GetCard(flushHandIndex + card));
                    }
                }
                else
                {
                    WriteLine("No Flush.");
                }
                WriteLine("是否繼續取牌,如果繼續請輸入y或Y!");
                str=ReadLine();
            }
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章