예제 #1
0
    public void DealerHitCards()
    {
        int y = 1;
        int cardValue;

        distance = 0.5f;

        x = blackJackController.cardTracker;
        //return the next card from the deck
        dealerCards[y] = cardController.ReturnCardfromDeck(x);

        secondDealerScore = int.Parse(dealerCards[y].GetComponent <CardManager>().ReturnCardValue());


        if ((firstDealerScore == 10 && secondDealerScore == 1) || (firstDealerScore == 1 && secondDealerScore == 10))
        {
            Debug.Log("Dealer has BlackJack");
            dealerStatus = "blackjack";
            dealerScore  = 21;

            //Spawn the dealer card
            Vector3    dealerNextCardLocation = new Vector3(firstDealerCardLocation.x + distance, firstDealerCardLocation.y, firstDealerCardLocation.z);
            GameObject dealerNextCard         = GameObject.Instantiate(dealerCards[y], dealerNextCardLocation, Quaternion.identity) as GameObject;

            dealerNextCard.GetComponent <SpriteRenderer>().sortingLayerName = sortingLayer[y];
            dealerNextCard.transform.SetParent(canvas.transform);

            ShowDealerStatus("blackjack");
        }

        else
        {
            while (dealerScore < 17)
            {
                x = blackJackController.cardTracker;

                //return the next card from the deck
                dealerCards[y] = cardController.ReturnCardfromDeck(x);

                //Spawn the dealer card
                Vector3    dealerNextCardLocation = new Vector3(firstDealerCardLocation.x + distance, firstDealerCardLocation.y, firstDealerCardLocation.z);
                GameObject dealerNextCard         = GameObject.Instantiate(dealerCards[y], dealerNextCardLocation, Quaternion.identity) as GameObject;

                dealerNextCard.GetComponent <SpriteRenderer>().sortingLayerName = sortingLayer[y];
                dealerNextCard.transform.SetParent(canvas.transform);

                //Returns the card value
                cardValue = int.Parse(dealerCards[y].GetComponent <CardManager>().ReturnCardValue());


                //Update the dealer score
                dealerScore = dealerScore + cardValue;

                //Update dealer status
                ShowDealerStatus(dealerScore.ToString());

                //Update counters
                blackJackController.cardTracker++;
                y++;
                distance = distance + 0.5f;
            }
        }
        //Check the dealer's score
        DealerScoreCheck();
        blackJackController.FinalScoreCheck();
    }