C#作业,急着交,哪位大神做过发我一份,有注释最好! 100
展开全部
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;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询