Esempio n. 1
0
    public IEnumerator Action()
    {
        // Check if it's the AI's turn
        if (Keys.GetBool("IsTurn"))
        {
            // Show the cards
            CardController.GetCardsInHand()[0].GetComponent <CardController>().ShowCard();
            yield return(new WaitForSeconds(ActionWaitTime));

            // Make sure that the controller is valid
            if (CardController != null)
            {
                // TODO: Check if everyone has busted
                // Get the current value & run a switch to see if there are any pre-determined actions, if there are then perform those actions
                // otherwise let the AI Decide based on their cards and the players cards.
                var total = CardController.GetCurrentValue();
                if (total > 17 || HasEveryoneBusted())
                {
                    AI_Stand();
                }
                else
                {
                    DetermineHit();
                }
            }
        }
    }
Esempio n. 2
0
    void CheckNaturals()
    {
        // Create an initial list
        List <GameObject> Naturals = new List <GameObject>();

        // Loop through each player in game & make sure that it isn't the dealer (as we will deal with them last, No pun intended)
        foreach (var p in GameManager.Instance.GetPlayersInGame())
        {
            PlayerController player = p.GetComponent <PlayerController>();
            if (player != null)
            {
                // If the value is equal to 21 than add them to the list of naturals
                if (p.GetComponent <PlayerCardController>().GetCurrentValue() == 21)
                {
                    Naturals.Add(p);
                }
            }
        }

        // Check if the dealer has a natural
        bool DealerHasNat = false;

        if (PlayerCards.GetCurrentValue() == 21)
        {
            DealerHasNat = true;
        }

        // If the dealer has natural than then the players get their last bet back
        // Otherise they get 2.5 back
        if (DealerHasNat)
        {
            foreach (var p in Naturals)
            {
                p.GetComponent <PlayerController>().AddChips(p.GetComponent <PlayerController>().GetLastBet());
            }
        }
        else
        {
            foreach (var p in Naturals)
            {
                p.GetComponent <PlayerController>().AddChips(Mathf.RoundToInt(p.GetComponent <PlayerController>().GetLastBet() * 2.5f));
            }
        }

        // TODO: Skip the player if they have a natural
    }