zoukankan      html  css  js  c++  java
  • c# 扑克牌程序(2) 发5张同花牌

    根据之前发表的文章《c# 扑克牌程序(1) 一副扑克牌可以选择是否包含大小王》中提供的类库,引用它。

    具体功能为:从打乱顺序(洗牌)的一副牌中一次取出5张牌,如果这5张牌是同花,就提示。

    否则,在取出50张牌后停止。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Ch10CardLib;      //类库
    namespace test1095
    {
        class Program
        {
            static void Main(string[] args)
            {
                int wCount = 0;
                while (true)
                {
                    wCount++;
                    Deck playDeck = new Deck();     //实例化Deck类
                    playDeck.Shuffle();             //洗牌
                    bool isFlush = false;           //实例一个bool值并初始化为false用于记录是否4张牌是同花
                    int flushHandIndex = 0;         //连续5张同花牌中第一张牌的索引位置
                    int count = 0;
                    for (int hand = 0; hand < 10; hand++)       //大循环10次,小循环4次
                    {
                        count++;
                        isFlush = true;
                        Suit flushSuit = playDeck.GetCard(hand * 5).suit;       //以每个循环起点的花色作为同花花色的标的色
                        for (int card = 1; card <5; card++)        //4次循环是否为连续同花色,只要有一张不同色就为false
                        {
                            count++;
                            if (playDeck.GetCard(hand * 5 + card).suit != flushSuit)
                            {
                                isFlush = false;
                            }
                        }
                        if (isFlush)
                        {
                            flushHandIndex = hand * 5;
                            break;
                        }
                    }
                    if (isFlush)
                    {
                        Console.WriteLine("Flush! 已循环"+count);
                        for (int card = 0; card < 5; card++)
                        {
                            Console.WriteLine(playDeck.GetCard(flushHandIndex + card));
                        }
                        Console.WriteLine("
    已洗牌{0}次,全部牌型:",wCount);
                        for(int card=0;card<54;card++)
                        {
                            Console.WriteLine(playDeck.GetCard(card)+" "+card);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No Flush! 已洗牌{0}次,已发牌{1}张" ,wCount,count);
                    }
                    Console.ReadKey();
                }
            }
        }
    }
    


     

  • 相关阅读:
    LeetCode_Spiral Matrix II
    省选模拟10 题解
    省选模拟9 题解
    省选模拟8 题解
    省选模拟7 题解
    省选模拟6 题解
    省选模拟5 题解
    省选模拟4 题解
    数学专题测试3 题解
    数学专题测试2 题解
  • 原文地址:https://www.cnblogs.com/ssxm831/p/3574528.html
Copyright © 2011-2022 走看看