示例#1
0
    public void DrawCard(HandController handController, bool ignoreDrawCount = true)
    {
        GameObject.FindObjectOfType <AudioController>().PlayCardAudio();

        int cardsToDraw = 1;

        if (!ignoreDrawCount && centerController.drawCount > 0)
        {
            cardsToDraw = centerController.drawCount;
            centerController.drawCount      = 0;
            centerController.cardEffectUsed = true;
        }

        for (int j = 0; j < cardsToDraw; j++)
        {
            GameObject card = GetTopCard();

            if (handController.tag != "Player")
            {
                card.GetComponent <SpriteRenderer>().sprite     = cardBack;
                card.GetComponent <DragController>().isDragable = false;
            }

            card.GetComponent <DragController>().handController   = handController;
            card.GetComponent <DragController>().centerController = centerController;
            handController.AddCardToHand(card);

            if (cards.Count == 1)
            {
                Debug.Log("Refilling draw pile");

                Card lastCard = cards[0];
                cards = centerController.AlreadyUsedCards;

                int count = cards.Count;
                int last  = count - 1;
                for (var i = 0; i < last; ++i)
                {
                    int  r   = UnityEngine.Random.Range(i, count);
                    Card tmp = cards[i];
                    cards[i] = cards[r];
                    cards[r] = tmp;
                }

                cards.Add(lastCard);
            }
        }
    }