一段扑克发牌机的旧代码,这个问题似乎学生习题比较常见,也可能被作为招聘考题考察 Coder 的思维。
代码很简单也没什么价值,不过用到了枚举、GUID和排序泛型类,对.NET初学者可能会有点参考作用。
using
System;
using
System.Collections.Generic;

public
class
PokeGame
{
enum PointText
{
A = 1,
J = 11,
Q,
K,
}

public enum Suits
{
Spade,
Hearts,
Clubs,
Diamonds,
}

public struct Poke
{
Suits Suit;
int Point;

public Poke(Suits suit, int point)
{
Suit = suit;
Point = point;
}

public override string ToString()
{
return Suit.ToString() + " " + ((PointText)Point).ToString();
}
}

private readonly int SimpleMaxCount = 13;

private Poke[] _dealer;

public Poke[] Dealer { get { return _dealer; } }

public PokeGame()
{
_dealer = new Poke[SimpleMaxCount * sizeof(Suits)];
SortedList<Guid, Poke> dealer = new SortedList<Guid, Poke>();
for (int i = 0; i < sizeof(Suits); i++)
{
for (int j = 0; j < SimpleMaxCount; j++)
{
dealer.Add(Guid.NewGuid(), new Poke((Suits)i, j + 1));
}
}
dealer.Values.CopyTo(_dealer, 0);
}
}
代码很简单也没什么价值,不过用到了枚举、GUID和排序泛型类,对.NET初学者可能会有点参考作用。


























































