C#打印一副扑克牌

  public enum PokerColor {

        黑桃,

        红心,

        梅花,

        方片

    }

 

    public enum PokerNum {

        A,

        Two,

        Three,

        Four,

        Five,

        Six,

        Seven,

        Eight,

        Nine,

        Ten,

        J,

        Q,

        K

    }

    //扑克类

    class Poker {

        //花色

        public PokerColor color;

        //大小

        public PokerNum num;

        public Poker(PokerColor _color,PokerNum _num){

            color = _color;

            num = _num;

        }

        //描述牌信息的方法

        public void DescriptePoker() {

            Console.WriteLine("{0}{1}",this.color,this.num);

        }

    }

 

    //表示一副扑克牌的类

    class Pokers {

        //定义一个数组来存放52张扑克牌

        Poker[] pokers = new Poker[52];

        //用于计数创建的扑克牌个数

        int index = 0;

 

        //一副扑克牌类的构造方法(创建一副扑克牌对象时调用)

        public Pokers() {

            //创建52张牌放到这副牌

            for (int i = 0; i < 4; i++)

            {

                //外层来控制花色

                for (int j = 0; j < 13; j++)

                {

                    PokerColor color = (PokerColor)i;

                    PokerNum num = (PokerNum)j;

                    //内层来控制牌面大小

                    Poker poker = new Poker(color,num);

                    pokers[index] = poker;

                    index++;

                }

            }

        }

 

        //洗牌

        public void Shuffle() {

 

        }

        //描述所有牌面信息的方法

        public void ShowPokers() {

            foreach (Poker item in this.pokers)

            {

                item.DescriptePoker();

            }

        }

    }

 

    class Program

    {

        static void Main(string[] args)

        {

            //来一副扑克牌

            Pokers pokers = new Pokers();

            //打印这幅牌中所有牌信息

            pokers.ShowPokers();

  

            Console.ReadKey();

        }

    }

 

 

你可能感兴趣的:(C#打印一副扑克牌)