Esempio n. 1
0
        private List <PlayingCard> Shuffle(ref List <PlayingCard> cardList)
        {
            var randomizer = new Random(DateTime.Now.Millisecond);

            List <PlayingCard> shuffledCards = new List <PlayingCard>();

            while (cardList.Any())
            {
                int         cardIndex = randomizer.Next(maxValue: cardList.Count);
                PlayingCard card      = cardList[cardIndex];
                shuffledCards.Add(card);
                cardList.Remove(card);
            }

            return(shuffledCards);
        }
Esempio n. 2
0
        public void NewDeck()
        {
            Cards.Clear();
            List <PlayingCard> allCards = new List <PlayingCard>(); // Blank list to hold the cards we fetch from the enum

            foreach (CardSuit mySuit in Enum.GetValues(typeof(CardSuit)))
            {
                foreach (CardRank myRank in Enum.GetValues(typeof(CardRank)))
                {
                    PlayingCard card = new PlayingCard(myRank, mySuit, CardBack, SpriteBatch);
                    allCards.Add(card);
                }
            }

            List <PlayingCard> shuffledCards = Shuffle(ref allCards);

            Cards = shuffledCards;
            //foreach (PlayingCard card in shuffledCards)
            //{
            //    PlayingCard newCard = new PlayingCard { CardType = card };
            //    Cards.Add(newCard);
            //    Console.WriteLine(newCard.CardType);
            //}
        }