改了个洗牌算法

//Card类

class Card
{
    public enum Suits
    {
        Spades,
        Clubs,
        Diamonds,
        hearts
    }
    public enum Values
    {
        Ace = 1,
        Two = 2,
        Three = 3,
        Four = 4,
        Five = 5,
        Six = 6,
        Seven = 7,
        Eight = 8,
        Nine = 9,
        Ten = 10,
        Jack = 11,
        Queen = 12,
        King = 13
    }
    public Suits Suit;
    public Values Value;
    public Random random = new Random();
    
    public Card(Suits Suit, Values Value)
    {
        this.Suit = Suit;
        this.Value = Value;
    }
    //public Card()
    //{
    //    this.Suit = (Suits)random.Next(4);
    //    this.Value = (Values)random.Next(1, 13);
    //}
    private string name;
    public string Name
    {
        get {
            name = Value.ToString() + " of " + Suit.ToString();
            return name; }
    }
}
//牌类及其洗牌算法
class Deck
{
    public List<Card> cards;
    public Deck()
    {
        cards = new List<Card>();
    }

    //洗牌算法1
    public Deck Shuffle1(Deck shuffleDeck)
    {
        List<Card> tempCards;
        Card card;
        Random random = new Random();
        int shuffleNumber = shuffleDeck.cards.Count;
        for (int i = 0; i < shuffleNumber; i++ )
        {
            tempCards = new List<Card>();
            while (shuffleDeck.cards.Count != 0)
            {
                int cardsNO = random.Next(shuffleDeck.cards.Count);
                card = shuffleDeck.cards[cardsNO];
                tempCards.Add(card);
                shuffleDeck.cards.Remove(card);
            }
            shuffleDeck.cards = tempCards;
            tempCards = null;
        }
        return shuffleDeck;
    }
}
posted @ 2010-11-18 18:05  桑羊  阅读(169)  评论(0编辑  收藏  举报