第二节课作业

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

namespace 第二节课作业
{
enum Suit
{
Spade, Heart, Diamond, Club
}
enum Value
{
Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queue, King, Ace
}
class Card
{
public Suit suit;
public Value value;
}
class Program
{
//是否为同花
public static bool isSuitSame (Card[] cs)
{
if (cs[0].suit == cs[1].suit && cs[1].suit == cs[2].suit && cs[2].suit == cs[3].suit && cs[3].suit == cs[4].suit)
{
return true;
}
return false;
}
//排序
public static Card[] Sort(Card[] cs)
{
Card temp;
for (int i = 0; i < cs.Length; i++)
{
for(int j=i+1;j<cs.Length;j++)
{
if (cs[i].value > cs[j].value)
{
temp = cs[i];
cs[i] = cs[j];
cs[j] = temp;
}
}
}
return cs;
}
//做减法
public static int[] Subtract(Card[] player)
{
int[] result = new int[4];
for (int i = 0; i < player.Length-1; i++)
{
result[i] = player[i + 1].value - player[i].value;
}
return result;
}

static void Main(string[] args)
{
Card[] cards = new Card[52];
//初始化一副牌
for (int i = 0; i < 52; i++)
{
cards[i] = new Card();
cards[i].suit = (Suit)(i / 13);
cards[i].value = (Value)(i % 13);
}

Random ran = new Random();
Card temp = new Card();
Card[] player = new Card[5];
int a ;
int symbol;
int[] result = new int[4];
Console.WriteLine("是否开始游戏(按1开始)");
symbol = int.Parse(Console.ReadLine());
//开始游戏循环
while(symbol==1)
{
a = 0;
//洗牌
for (int i = 51; i > 0; i--)
{
int j = ran.Next(i);
temp = cards[i];
cards[i] = cards[j];
cards[j] = temp;
}
while (a != 100)
{
int i = ran.Next(51);
int j = ran.Next(51);
if (i != j)
{
temp = cards[i];
cards[i] = cards[j];
cards[j] = temp;
a++;
}
}
//发牌
for (int i = 0; i < 5; i++)
{
player[i] = cards[i];
}
player = Sort(player);
//判断是什么牌
result = Subtract(player);
if (result[0] == result[1] && result[1] == result[2] && result[2] == result[3] && result[3] == 1)
{
if (isSuitSame(player))
{
Console.WriteLine("同花顺");
}
else
{
Console.WriteLine("顺子");
}
}
else if ((result[0] == result[1] && result[1] == result[2] && result[2] == 0) ||
(result[1] == result[2] && result[2] == result[3] && result[3] == 0))
{
Console.WriteLine("四条");
}
else if ((result[0] == result[1] && result[1] == result[3] && result[3] == 0) ||
(result[0] == result[2] && result[2] == result[3] && result[0] == 0))
{
Console.WriteLine("满堂红");
}
else if ((result[0] == result[1] && result[1] == 0) || (result[1] == result[2] && result[2] == 0)
|| (result[2] == result[3] && result[3] == 0))
{
Console.WriteLine("三条");
}
else if ((result[0] == 0 && result[2] == 0) || (result[0] == 0 && result[3] == 0) ||
(result[1] == 0 && result[3] == 0))
{
Console.WriteLine("两对");
}
else if (result[0] == 0 || result[1] == 0 || result[2] == 0 || result[3] == 0)
{
Console.WriteLine("一对");
}
else
{
if (isSuitSame(player))
{
Console.WriteLine("同花");
}
else
{
Console.WriteLine("无对");
}
}
for (int j = 0; j < 5; j++)
{
Console.WriteLine("{0}:{1}", player[j].suit, player[j].value);
}
Console.WriteLine("是否继续游戏(按1继续)");
symbol= int.Parse(Console.ReadLine());
}
Console.ReadKey();
}
}
}

转载于:https://www.cnblogs.com/zhaohaijie/p/6555484.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值