永发信息网

求C# 发桥牌程序代码

答案:2  悬赏:60  手机版
解决时间 2021-04-27 07:13
求C# 发桥牌程序代码
最佳答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ch1p392_2
{
    class Program
    {
    static void Main(string[] args)
    {
    char[] a = { 'C', 'D', 'H', 'S' }; //代表花色,C 代表梅花,D 代表方块,H 代表红心,S 代表黑桃
    char[] b = { 'A', '2', '3', '4', '5', '6', '7', '8', '9', '1', 'J', 'Q', 'K' };//代表一条花色13张牌
    int[] c = { 1, 2, 3, 4 }; //代表四个人
    int[] d = new int[52]; //代表52张牌
    int i , j;//循环变量
    int count = 0;//累加发牌次数用来判断换行
    Random r = new Random(unchecked((int)DateTime.Now.Ticks));//取随机数
    for (i = 0; i < 52; i++)
    {
    while (c[j = r.Next(1, 4)] % 4 <= 0)//  判断是否小于等于零是没用的因为是取不到0这个数的,
    //其实就是为了表达式合法化才这样写的
    c[j]++;
    d[i] = j;
    }
    for (j = 0; j < 4; j++)
    {
    for (i = 0; i < 52; i++)
    {
    if (d[i] != j)
    continue;
    Console.Write(a[i / 13]);
    Console.Write(b[i % 13]);
    if (i % 13 == 9)
    Console.Write('0');
    count++;
    if (count >= 13)
    {
    Console.WriteLine(); //只要发牌到达13张就打印一次换行
    count = 0;  //在吧count的值初始化为零
    }
    Console.Write("   ");//控制打印出来的字符和字符之间的位置
    }
    }
    }
    }
}

全部回答

 public class PokeGame     {     public enum Suits    //花色     {     Spade,     Hearts,     Clubs,     Diamonds     }     public enum PointText   //点数     {     A=1,     J=11,     Q=12,     K=13     }     public struct Poke   //扑克牌     {     Suits suit;     int point;     public Poke(Suits s, int p)     {     suit = s;     point = p;     }     public override string ToString()     {     return suit.ToString() + "  " + ((PointText)point).ToString();     }     }

    private readonly int MaxCount = 13;     private Poke[] _test;

    public Poke[] Test     {     get { return _test; }     }

    public PokeGame()     {     _test=new Poke[MaxCount  *  sizeof(Suits)];// 尽量不写死     SortedList<Guid, Poke> t = new SortedList<Guid, Poke>();     for (int i = 0; i < sizeof(Suits); i++)     {     for (int j = 0; j < MaxCount; j++)     {     t.Add(Guid.NewGuid(), new Poke((Suits)i, j + 1));     }     }     t.Values.CopyTo(_test, 0);     }

    static void Main(string[] args)     {     PokeGame pg = new PokeGame();     PokeGame.Poke[] ps = pg.Test;     //foreach (PokeGame.Poke p in ps)     //{     //    Console.WriteLine(p.ToString());     //}     for (int i = 1; i < 5; i++)     {     Console.WriteLine("第"+i +":");     for(  int  j=(i-1)*13; j<i*13;   j++)     Console.WriteLine(ps[j]);     Console.WriteLine("==========================");     }     }

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
有关英勇杀敌的句子,XP会不会比98更加充分的
五福酒行地址在哪,我要去那里办事
2009 6月我 什么时候能领生日礼物
徐州城东区有两个湖是哪两个湖?
刚转职的狂战怎么加点
真情会输给世俗吗
电影频道怎么没了
电影传入中国的详细过程
男孩和女孩刚开始谈恋爱,男孩首先应该做些什
读大学真的有前途吗
我用了优化大师内存整理感觉很卡~
初三B班的课应该怎么上,才能达到双赢?
我打开我的qq空间,上面图标显示的竟然是新浪
六三酒家在哪里啊,我有事要去这个地方
建安宿舍这个地址在什么地方,我要处理点事
推荐资讯
有一部描写曹雪芹的电视剧吗?名字不叫曹雪芹
为什么古人写错字叫通假字
刘德华经典的歌曲
7979酒类直供邵阳紫东店在哪里啊,我有事要去
起名婉字五行属性
真正爱一个人会为他放弃一切吗?
佳能的IXUS的价位是多少?
减肚子上的肥肉圈要怎么练最有效……
为什么我家的电脑会自动关机啊(而且不是正常
为什么人总要装裱自己的内心?
中国农业银行万全县支行我想知道这个在什么地
我想做应援的毛巾、但是不知道哪里有厂家、价
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?