Exemplo n.º 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);
        }
Exemplo n.º 2
0
        protected virtual void DealGame()
        {
            // shuffle the draw pile
            DrawPile.Shuffle(Randomizer);

            if (Config.ShufflePlayerList)
            {
                Pile <Player> .Shuffle(Players, Randomizer);
            }

            // distribute the cards
            foreach (var player in Players)
            {
                var drawnCards = DrawCards(Config.InitialDealSize);
                player.Hand.UnionWith(drawnCards);
            }

            // draw one card and discard it; this will be our top card
            var newTopCard = DrawCard();

            if (newTopCard.Color == CardColor.Wild)
            {
                // it's a wild card; give it a fixed color at random
                newTopCard = new Card((CardColor)Randomizer.Next(0, 4), newTopCard.Value);
            }
            DiscardPile.Push(newTopCard);

            CurrentGameState = GameState.InProgress;

            // we're getting ready to start!
            BroadcastAnchorCardsDealtEvent();

            // start a new turn!
            StartNewTurn();
        }