洗牌当然就成了第一个要完成的动作了,在网上找了一下,找到一篇园子里一位朋友写的文章(扑克牌的随机发牌程序),看看后,感觉有点麻烦,于是自己写了一个,实在是简单,就不多做解释了。代码如下:
class Poker
{
/// <summary>
/// 记录54张牌
/// </summary>
private int[] _cards = new int[54] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
public Poker()
{ }
public void Reshuffle()
{
Random ram = new Random();
int currentIndex;
int tempValue;
for (int i = 0; i < 54; i++)
{
currentIndex = ram.Next(0, 54 - i);
tempValue = _cards[currentIndex];
_cards[currentIndex] = _cards[53 - i];
_cards[53 - i] = tempValue;
}
}
}
PS:在文章里怎么添加代码呢?搞忘记了哦,哪位兄弟告诉一声。