class card
{
public int ds; //存储点数,范围1-13
public int hs; //存储花色,为了方便比较大小,使用int类型来表示,1表示方块,2表示梅花,3表示红桃,4表示黑桃
//默认的构造函数
public card()
{
}
//带参数的构造函数,便于初始化的时候直接赋值
public card(int d, int h)
{
ds = d;
hs = h;
}
//根据hs和ds值,来获得某张扑克牌的点数或花色
public string getCard()
{
string vhs;
string vds;
if (hs == 1)
{
vhs = "方块";
}
else if (hs == 2)
{
vhs = "梅花";
}
else if (hs == 3)
{
vhs = "红桃";
}
else if (hs == 4)
{
vhs = "红桃";
}
else
{
vhs = "非法牌";
}
if (ds == 11)
{
vds = "J";
}
else if (ds == 12)
{
vds = "Q";
}
else if (ds == 13)
{
vds = "K";
}
else if (ds == 1)
{
vds = "A";
}
else
{
vds = ds.ToString();
}
return vhs + vds;
}
}
//一副扑克牌类
class pkp
{
//一副扑克牌有52张
public card[] cd;
//重写构造函数
public pkp()
{
cd = new card[52];
////1~13,全部都是方块
//for (int i = 0; i <= 13; i++)
//{
// cd[i] = new card(i + 1, 1);
//}
////14~26,全部都是梅花
//for (int i = 13; i < 26; i++)
//{
// cd[i] = new card(i - 12, 2);
//}
////26~39,全部都是红桃
//for (int i = 26;i<39;i++)
//{
// cd[i] = new card(i - 26, 3);
//}
////40~52,全部都是黑桃
//for (int i = 39; i < 52; i++)
//{
// cd[i] = new card(i - 38, 4);
//}
for (int i = 0; i < 13; i++)
{
cd[i] = new card(i + 1, 1); //1~13,全部都是方块
cd[i + 13] = new card(i + 1, 2); //14~26,全部都是梅花
cd[i + 26] = new card(i + 1, 3); //26~39,全部都是红桃
cd[i + 39] = new card(i + 1, 4); //40~52,全部都是黑桃
}
}
public void xp()
{
Random r = new Random();
int a = r.Next(0, 52);
int b = r.Next(0, 52);
card tmp;
tmp= cd[a];
cd[a] = cd[b];
cd[b] = tmp;
}
}
class Program
{
static void Main(string[] args)
{
//card cd1 = new card();
//cd1.hs = 4;
//cd1.ds = 1;
//string a = cd1.getCard();
//Console.WriteLine(a);
//card cd2 = new card(11, 3);
//a = cd2.getCard();
//Console.WriteLine(a);
pkp p = new pkp();
p.xp();
Console.WriteLine("扑克牌游戏开始...");
//pkp p = new pkp();
Console.WriteLine("牌已经洗好了...");
p.xp();
int pai1;
int pai2;
while (true)
{
Console.Write("玩家一请抽牌(1-52):");
try
{
pai1 = Convert.ToInt32(Console.ReadLine());
if (pai1 > 52 || pai1 < 1)
{
Console.WriteLine("请输入数值的范围为1~52...");
continue;
}
else
{
break;
}
}
catch (Exception)
{
Console.WriteLine("请输入整数类型...");
}
}
Console.Write("玩家一抽到的牌是:{0}", p.cd[pai1 - 1].getCard());
while (true)
{
Console.Write("玩家二请抽牌(1-52):");
try
{
pai2 = Convert.ToInt32(Console.ReadLine());
if (pai2 > 52 || pai2 < 1)
{
Console.WriteLine("请输入数值的范围为1~52...");
continue;
}
else
{
break;
}
}
catch (Exception)
{
Console.WriteLine("请输入整数类型...");
}
}
Console.Write("玩家二抽到的牌是:{0}", p.cd[pai2 - 1].getCard());
Console.ReadLine();
for (int i = 0; i < 52; i++)
{
Console.WriteLine(p.cd[i].getCard());
}
}
}