C#作业,急着交,哪位大神做过发我一份,有注释最好! 100

 我来答
玩转数据处理
2015-03-14 · 数据处理,Python,dotnet
玩转数据处理
采纳数:1613 获赞数:3794

向TA提问 私信TA
展开全部
using System;
using System.Collections.Generic;
using System.Text;

namespace _21Point
{
    class Program
    {
        static List<string> list = null;
        static List<string> listZhuangjia = null;
        static List<string> listXianjia = null;
        static readonly string[] card = new string[] { "黑桃", "红桃", "梅花", "方块" };
        static readonly string[] number = new string[] { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };

        static void Main(string[] args)
        {
            list = new List<string>();
            listZhuangjia = new List<string>();
            listXianjia = new List<string>();
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("*******************alkaj;sdkfa;sdkfa;dka;lkdfasdl**********************");
            Console.WriteLine("开始发牌,庄闲各两张牌……");
            list = GetAllCards();
            ArrRandom(list);
            for (int i = 0; i < 2; i++)
            {
                PlayerGetCard(listZhuangjia);
                PlayerGetCard(listXianjia);
            }
            Console.WriteLine("庄家: 底牌\t{0}", listZhuangjia[1]);
            Console.WriteLine("闲家: {0} \t{1}\n", listXianjia[0], listXianjia[1]);
        choice:
            Console.Write("请选择(1.停牌  2.要牌)");
            string getCard = Console.ReadLine();
            if (getCard == "2")
            {
                PlayerGetCard(listXianjia);
                ShowPlayPoints(listXianjia, "闲家");
                if (ComputePoint(listXianjia) > 21)
                {
                    Console.WriteLine("过了!!!");
                    Console.WriteLine("庄家赢");
                    Console.WriteLine("是否下一局(Y/N):");
                    string next = Console.ReadLine();
                    if (next.ToUpper() == "Y")
                    {

                    }
                    else if (next.ToUpper() == "N")
                    {
                        return;
                    }
                }
                else
                {
                    goto choice;
                }
            }
            Console.ReadKey();
        }

        private static void ShowPlayPoints(List<string> player, string playerName)
        {
            foreach (var item in player)
            {
                Console.Write(item + "\t");
            }
            Console.WriteLine("({0}点数:{1})", playerName, ComputePoint(player));
        }

        private static int ComputePoint(List<string> player)
        {
            int sum = 0;
            foreach (var item in player)
            {
                string temp = item.Substring(2, item.Length-2);
                switch (temp)
                {
                    case "A":
                        sum += 1;
                        break;
                    case "J":
                    case "Q":
                    case "K":
                        sum += 10;
                        break;
                    default:
                        sum += Convert.ToInt32(temp);
                        break;
                }
            }
            return sum;
        }

        private static void ArrRandom(List<string> arr)
        {
            Random ran = new Random();
            int k = 0;
            string strtmp = "";
            for (int i = 0; i < arr.Count; i++)
            {
                k = ran.Next(0, 20);
                if (k != i)
                {
                    strtmp = arr[i];
                    arr[i] = arr[k];
                    arr[k] = strtmp;
                }
            }
        }

        static void PlayerGetCard(List<string> player)
        {
            Random r = new Random();
            int index = r.Next(list.Count);
            player.Add(list[index]);
            list.RemoveAt(index);
        }

        static List<string> GetAllCards()
        {
            List<string> temp = new List<string>();
            string tt = string.Empty;
            for (int i = 0; i < 13; i++)
            {
                string tmp = string.Empty;
                foreach (var item in card)
                {
                    temp.Add(item + number[i]);
                }
            }
            return temp;
        }
    }
}
HymanZheng
2015-03-14 · TA获得超过126个赞
知道小有建树答主
回答量:236
采纳率:66%
帮助的人:77.4万
展开全部
多久时间,我没写过,可以现在试试?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式