C#作业,哪位大神有源代码,发我一份!有注释最好! 100
花了近1小时完成的(我这的vs2010有问题。。郁闷。。)
一定要采纳啊!
代码如下
-----------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication_21点游戏
{
class Program
{
static void Main(string[] args)
{
Start:
Console.Clear();
//初始化数组,将对应花色的各13张牌放入数组
for (int i = 0; i < zhuangjia.Length; i++)
{
zhuangjia[i] = null;
zhuangjia_point[i] = 0;
}
for (int i = 0; i < xianjia.Length; i++)
{
xianjia[i] = null;
xianjia_point[i] = 0;
}
zhuangjia_n = 0;
xianjia_n = 0;
for (int i = 0; i < 13; i++)
{
hongtao[i] = i++;
}
for (int i = 0; i < 13; i++)
{
fangkuai[i] = i++;
}
for (int i = 0; i < 13; i++)
{
meihua[i] = i++;
}
for (int i = 0; i < 13; i++)
{
heitao[i] = i++;
}
Console.WriteLine("初始发牌:");
for (int i = 0; i < 2; i++)
{
zhuangjia[i] = SendCard("zhuangjia");
}
Console.WriteLine("庄家:{0} {1}", "底牌", zhuangjia[1]);
for (int i = 0; i < 2; i++)
{
xianjia[i] = SendCard("xianjia");
}
Console.WriteLine("闲家:{0} {1}", xianjia[0],xianjia[1]);
Console.WriteLine("游戏开始!");
int number = 0;
for (int i = 2; i < 5; i++)
{
number++;
Console.WriteLine();
Console.WriteLine("第{0}轮开始!",number);
Console.Write("闲家是否要牌?<Y/N>");
string choose=Console.ReadLine();
switch (choose)
{
case "Y":
break;
case "N":
Console.WriteLine("闲家");
goto Next;
}
xianjia[i]=SendCard("xianjia");
Console.WriteLine("你得到了:{0}",xianjia[i]);
Console.Write("闲家:");
foreach (string item in xianjia)
{
Console.Write(item+" ");
}
Console.WriteLine();
int xianjia_zongfen = 0;
foreach (int item in xianjia_point)
{
xianjia_zongfen += item;
}
if (xianjia_zongfen>21)
{
Console.WriteLine("闲家的总分是:"+xianjia_zongfen.ToString());
Console.WriteLine("超过了21!爆牌!");
Console.WriteLine("闲家输了!庄家赢了!");
goto Endchoose;
}
Next:
zhuangjia[i] = SendCard("zhuangjia");
int zhuangjia_zongfen=0;
foreach (int item1 in zhuangjia_point)
{
zhuangjia_zongfen += item1;
}
if (zhuangjia_zongfen > 21)
{
zhuangjia[i] = null;
zhuangjia_point[i] = 0;
Console.WriteLine("庄家停牌!");
goto End;
}
else
{
Console.WriteLine("庄家得到了:"+zhuangjia[i]);
Console.Write("庄家:");
foreach (string item in zhuangjia)
{
Console.Write(item+" ");
}
Console.WriteLine();
}
}
End:
Console.WriteLine("游戏结束!");
Console.WriteLine("开始结算:");
int xianjiazongfen = 0;
foreach (int item in xianjia_point)
{
xianjiazongfen += item;
}
Console.WriteLine("玩家总分:{0}",xianjiazongfen);
int zhuangjiazongfen = 0;
foreach (int item in zhuangjia_point)
{
zhuangjiazongfen += item;
}
Console.WriteLine("庄家总分:"+zhuangjiazongfen);
if (xianjiazongfen>zhuangjiazongfen)
{
Console.WriteLine("闲家赢了!");
goto Endchoose;
}
if (xianjiazongfen<zhuangjiazongfen)
{
Console.WriteLine("庄家赢了!");
goto Endchoose;
}
if (xianjiazongfen==zhuangjiazongfen)
{
Console.WriteLine("平局!");
goto Endchoose;
}
Endchoose:
Console.Write("是否再来一局?<Y/N>");
string endchoose=Console.ReadLine();
switch (endchoose)
{
case "Y":
goto Start;
case "N":
break;
default:
goto Endchoose;
}
Console.ReadKey();
}
static string SendCard(string to)
{
string card=null;
Random r1 = new Random();
start:
int point=r1.Next(0,13);
switch(r1.Next(0,3))
{
case 0:
if (hongtao[point]==0)
{
goto start;
}
card = color[0]+hongtao[point].ToString();
hongtao[point] = 0;
break;
case 1:
if (fangkuai[point]==0)
{
goto start;
}
card = color[1]+fangkuai[point].ToString();
fangkuai[point] = 0;
break;
case 2:
if (heitao[point]==0)
{
goto start;
}
card = color[2]+heitao[point].ToString();
heitao[point] = 0;
break;
case 3:
if (meihua[point]==0)
{
goto start;
}
card = color[3] + meihua[point];
meihua[point] = 0;
break;
}
if (point == 11||point==12||point==13)
{
point = 10;
}
switch (to)
{
case "zhuangjia":
zhuangjia_point[zhuangjia_n] = point;
zhuangjia_n++;
break;
case "xianjia":
xianjia_point[xianjia_n] = point;
xianjia_n++;
break;
}
return card;
}
static int zhuangjia_n = 0;
static int xianjia_n = 0;
static string[] color = new string[4] { "红桃", "方块", "黑桃", "梅花" }; //声明变量,用于存放颜色
static int[] fangkuai = new int[13]; //声明数组,代表四个花色
static int[] hongtao = new int[13];
static int[] heitao = new int[13];
static int[] meihua = new int[13];
static string[] zhuangjia = new string[5];
static int[] zhuangjia_point = new int[5];
static string[] xianjia = new string[5];
static int[] xianjia_point = new int[5];
}
}
----------------------------------------------------------------------------------------------------------------
注释写的不怎么详细,A和JQK只能显示为1,11,12,13,因还有其他事情,请见谅!
最后说一句:这是我辛苦劳动的成果,一定要采纳啊!
2023-06-12 广告