自动发牌(C#版)

2016-11-30 来源: Galaxias 发布在  http://www.cnblogs.com/xinxin521/p/6117719.html

利用数组实现发牌过程

一副牌去掉大小王,还剩52张。一共东、南、西、北四家,每家随机发13张牌。

提示:

  1. 东、南、西、北四家用一维数组表示
  2. 每家的牌采用一维数组表示(13张) 
  3. 花色:enum Suit { Clubs, Diamonds, Hearts, Spades } 
  4. 牌面:enum Value { Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace }
  5. 每张牌可以独立作为一个类来实现,该类中包含两个成员,即花色和牌面
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace Poke
 {
     class Program
     {
         static void Main(string[] args)
         {
             Poker[] poker = ];
             shuffle(poker);

             //发牌
             Person[] person = ];
             ; i < ; i++)
             {
                 person[i] = new Person();
                 person[i].perPoker = ];
             }
             ; i < ; i++)
             {
                  == )
                     person[].perPoker[person[].count++] = poker[i];
                  == )
                     person[].perPoker[person[].count++] = poker[i];
                  == )
                     person[].perPoker[person[].count++] = poker[i];
                  == )
                     person[].perPoker[person[].count++] = poker[i];
             }
             //显示每个人的牌
             ; i < ; i++)
             {
                 Console.Write();
                 ; j < ; j++)
                 {
                     Console.Write(person[i].perPoker[j] + "\t");
                 }
                 Console.WriteLine();
             }
             Console.ReadKey();
         }
         //洗牌
         static void shuffle(Poker[] poker)
         {
             //设置52张牌
             ; i < ; i++)
                 ; j < ; j++)
                     poker[i *  + j] = );
             ; i <= ; i++)
             {
                 Random random = new Random();
                 , );
                 Poker temp = poker[i - ];
                 poker[i - ] = poker[num-];
                 poker[num-] = temp;
             }
         }
     }

     //花色
     enum Suit { Clubs, Diamonds, Hearts, Spades }

     //牌的值
     , Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King }

     //扑克牌类
     class Poker
     {
         public Suit suit;
         public Value value;

         public Poker() { }
         public Poker(Suit i, Value v)
         {
             suit = i;
             value = v;
         }

         public override string  ToString()
         {
              return (suit.ToString()+","+value.ToString());
         }
     }

     class Person
     {
         public Person(){}
         public Poker[] perPoker;
         public int count;
     }
 }

相关文章