Exemplo n.º 1
0
    private void DrawToHand(int amount)
    {
        int totalAmountDrawn = Math.Min(amount, deck_.Count + discardPile_.Count);

        // Early exit if nothing in draw pile or discard pile.
        if (totalAmountDrawn == 0)
        {
            return;
        }

        // TODO: implement max hand size

        // Try to draw from deck if available.
        int firstDrawAmount = Math.Min(amount, deck_.Count);

        if (firstDrawAmount > 0)
        {
            Card[] cardsDrawn = deck_.Draw(firstDrawAmount);
            hand_.Add(cardsDrawn);
            uiManager_.DrawFromDeckToHand(cardsDrawn,
                                          deck_.Count, firstDrawAmount);
        }

        // Shuffle discard to deck, draw remaining cards
        if (firstDrawAmount < amount)
        {
            totalAmountDrawn = Math.Min(amount, deck_.Count + discardPile_.Count);

            // Early exit if nothing in draw pile or discard pile.
            if (totalAmountDrawn == 0)
            {
                return;
            }

            deck_.Shuffle(discardPile_.Empty());
            uiManager_.ShuffleDiscardPileToDeck(deck_.Cards);

            Card[] cardsDrawn = deck_.Draw(amount - firstDrawAmount);
            hand_.Add(cardsDrawn);
            uiManager_.DrawFromDeckToHand(cardsDrawn,
                                          deck_.Count, amount - firstDrawAmount);
        }
    }