如何识别扑克牌中黑桃、红桃、草花、红片那位大哥能给一个类
解决方案 »
- 请问如何在DataTable的Expression表达式中取某列的绝对值。
- ReportDocument绑定数据源错误
- 如何将string写入到Word中
- 输入字母或拼音,显示对应的汉字
- DataGridView如何根据DataTable的变化而时时变化(windows程序)
- 读取这种结构的xml文档
- __designer:wfdid="w1" 是什么意思啊
- 问一个弱智的问题,vs2005怎么调置启动窗体?
- C#往Excel输出时,前面加一个特殊符号,就能当作纯文本,而不至于把数字文本当成数字显示.请问是哪个特殊符号?
- 跨平台问题:用C#控制台调用J2EE Web Service时,将对象数组序列化传递至Web Service中时,无法正常序列化,也就不能生成Soap包,怎么解
- 用vs2008+c#+winfrom做了个程序,想请教发布的相关问题,先感谢了!
- C# 别鄙视菜鸟!!!!因为你当初也是菜鸟!
public enum PokerColor
{
//黑桃
Spade=0,
//红心
Heart=1,
//草花
Club=2,
//方块
Diamond=3
}
LZ正解,
然后你的牌也一样用枚举。
例如public enum PokerValue
{
one,two,three,four....
}
public class puke()
{
public int whatPuke(int t)
{
int i=t;
if(i==1)
// 黑
if(i==2)
// 红
if(i==3)
// 花
if(i==4)
// 片
return i;
}}
using System;
using System.Collections.Generic;
using System.Text;namespace 扑克牌
{
public class Card
{
public readonly Suit suit;
public readonly Rank rank;
public Card(Suit newSuit, Rank newRank)
{
suit = newSuit;
rank = newRank;
}
public Card()
{
}
public override string ToString()
{
return "The " + rank + " of " + suit + "s";
}
}
}
using System.Collections.Generic;
using System.Text;namespace 扑克牌
{
public class Deck
{
private Card[] cards;
public Deck()
{
cards = new Card[52];
for (int suitVal = 0; suitVal < 4; suitVal++)
{
for (int rankVal = 1; rankVal < 14; rankVal++)
{
cards[suitVal * 13 + rankVal - 1] = new Card((Suit)suitVal, (Rank)rankVal);
}
}
} public Card GetCard(int cardNum)
{
if (cardNum >= 0 && cardNum <= 51)
return cards[cardNum];
else
throw (new System.ArgumentOutOfRangeException("cardNum", cardNum, "Value must be between 0 and 51"));
} public void Shuffle()
{
Card[] newDeck = new Card[52];
bool[] assigned = new bool[52];
Random sourceGen = new Random();
for (int i = 0; i < 52; i++)
{
int destCard = 0;
bool foundCard = false;
while (foundCard == false)
{
destCard = sourceGen.Next(52);
if (assigned[destCard] == false)
foundCard = true; }
assigned[destCard] = true;
newDeck[destCard] = cards[i];
}
newDeck.CopyTo(cards, 0);
}
}
}
using System.Collections.Generic;
using System.Text;namespace 扑克牌
{
public enum Rank
{
Ace = 1,
Deuce,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
}
}
using System;
using System.Collections.Generic;
using System.Text;namespace 扑克牌
{
public enum Suit
{
Club,
Diamond,
Heart,
Spade,
}
}
using System;
using System.Collections.Generic;
using System.Text;
using 扑克牌;namespace Client
{
class Program
{
static void Main(string[] args)
{
Deck MyDeck = new Deck();
MyDeck.Shuffle();
for (int i = 0; i < 52; i++)
{
Card tempCard = MyDeck.GetCard(i);
Console.Write(tempCard.ToString());
if (i != 51)
Console.Write(",");
else
Console.WriteLine();
}
Console.ReadKey();
}
}
}