Example #1
0
        protected virtual List <Card> DrawCards(int count)
        {
            var ret            = new List <Card>();
            int remainingCount = count;

            if (DrawPile.Count < remainingCount)
            {
                // draw the whole pile
                ret.AddRange(DrawPile.DrawAll());

                // shift all the cards from the discard into the draw pile except the top one
                // wild cards become discolored during this
                var discardTop = DiscardPile.Draw();
                DrawPile.AddRange(DiscardPile.DrawAll().Select(c => c.Value.IsWild() ? new Card(CardColor.Wild, c.Value) : c));
                DiscardPile.Push(discardTop);

                // shuffle the draw pile
                DrawPile.Shuffle(Randomizer);
            }

            remainingCount = Math.Max(count - ret.Count, 0);

            if (DrawPile.Count < remainingCount)
            {
                // oh well, take what's left
                ret.AddRange(DrawPile.DrawAll());
            }
            else
            {
                // take only what we need
                ret.AddRange(DrawPile.DrawMany(remainingCount));
            }

            return(ret);
        }
Example #2
0
        protected virtual void PrepareRegularPiles()
        {
            DrawPile.Clear();
            DiscardPile.Clear();

            // of each color:
            foreach (var color in RegularColors)
            {
                // one zero
                DrawPile.Push(new Card(color, CardValue.Zero));

                // two of:
                for (int i = 0; i < 2; ++i)
                {
                    // each number except zero
                    for (CardValue value = CardValue.One; value <= CardValue.Nine; ++value)
                    {
                        DrawPile.Push(new Card(color, value));
                    }

                    // skip, reverse draw-two
                    DrawPile.Push(new Card(color, CardValue.Skip));
                    DrawPile.Push(new Card(color, CardValue.Reverse));
                    DrawPile.Push(new Card(color, CardValue.DrawTwo));
                }
            }

            // four wilds, four wild-draw-fours
            for (int i = 0; i < 4; ++i)
            {
                DrawPile.Push(new Card(CardColor.Wild, CardValue.Wild));
                DrawPile.Push(new Card(CardColor.Wild, CardValue.WildDrawFour));
            }

            // assert the validity of the piles
            AssertPileValidity();
        }