Exemplo n.º 1
0
    public void UpdateState(float deltaTime)
    {
        if (FirstTime)
        {
            dealer.players[dealer.DealerIndex].GetComponent <PlayerController>().Hand.FlipUp();
            dealer.UpdateTotal(dealer.DealerIndex);
            FirstTime = false;
        }

        if (dealer.players[dealer.DealerIndex].GetComponent <PlayerController>().Hand.Total >= 17)
        {
            ToEndHand();
            return;
        }

        timer -= deltaTime;
        if (timer <= 0)
        {
            card = dealer.DealCard();
            dealer.cardGameObjectMap[card].transform.SetParent(dealer.players[dealer.DealerIndex].transform.FindChild("Table/Hand").transform);
            dealer.players[dealer.DealerIndex].GetComponent <PlayerController>().Hand.Add(card);
            dealer.UpdateTotal(dealer.DealerIndex);
            timer = coolDown;
        }

        // Check if the Player busts, got to end hand.
        if (dealer.players[dealer.DealerIndex].GetComponent <PlayerController>().Hand.Total > 21)
        {
            dealer.transform.Find("Table/GameStatusText").gameObject.GetComponent <Text>().text += dealer.players[dealer.DealerIndex].name + " Busted!\n";
            ToEndHand();
            return;
        }
    }
Exemplo n.º 2
0
    public void UpdateState(float deltaTime)
    {
        if (FirstTime)
        {
            dealer.HitButton.gameObject.SetActive(true);
            dealer.StandButton.gameObject.SetActive(true);
            dealer.GetComponent <DealerController>().UpdateBank();
            FirstTime = false;
        }

        if (dealer.players[0].GetComponent <PlayerController>().Hand.cards.Count == 2)
        {
            // Check if player got a BlackJack
            if (dealer.HasBlackJack(0))
            {
                dealer.transform.Find("Table/GameStatusText").gameObject.GetComponent <Text>().text += dealer.players[0].name + " has Blackjack!\n";
                ToDealerTurn();
                return;
            }

            // Check if player can Double Down.
            if (((dealer.Bet * 2) < dealer.players[0].GetComponent <PlayerController>().Bank) && (dealer.players[0].GetComponent <PlayerController>().Hand.Total >= 9 && dealer.players[0].GetComponent <PlayerController>().Hand.Total <= 11))
            {
                dealer.DoubleDownButton.gameObject.SetActive(true);
            }

            // Check if player did Double Down.
            if (dealer.DoublingDown)
            {
                dealer.GetComponent <DealerController>().SaveBet();
                dealer.GetComponent <DealerController>().UpdateBank(dealer.GetComponent <DealerController>().Bet * -1);
                //dealer.GetComponent<DealerController>().Bet *= 2;
                //dealer.BetField.text = dealer.GetComponent<DealerController>().Bet.ToString("0.00");
                card = dealer.DealCard();
                dealer.cardGameObjectMap[card].transform.SetParent(dealer.players[0].GetComponent <PlayerController>().CurrentPlayField.transform);
                dealer.players[0].GetComponent <PlayerController>().Hand.Add(card);
                dealer.players[0].GetComponent <PlayerController>().Hand.Bet *= 2;
                dealer.UpdateTotal(0);
                dealer.DoubleDownButton.gameObject.SetActive(false);
            }

            // Check if player can Split
            if ((PlayerController.Instance.NumberHands < 4) &&
                ((dealer.Bet * 2) < dealer.players[0].GetComponent <PlayerController>().Bank) &&
                (dealer.players[0].GetComponent <PlayerController>().Hand.cards[0].Value == dealer.players[0].GetComponent <PlayerController>().Hand.cards[1].Value))
            {
                dealer.SplitButton.gameObject.SetActive(true);
            }
            else
            {
                dealer.SplitButton.gameObject.SetActive(false);
            }

            // Check if player did Split
            if (dealer.Splitting)
            {
                dealer.GetComponent <DealerController>().UpdateBank();
                PlayerController.Instance.SplitHand();
                dealer.UpdateTotal(0);
                dealer.DoubleDownButton.gameObject.SetActive(false);
                dealer.SplitButton.gameObject.SetActive(false);
                dealer.Splitting = false;
            }
        }
        else
        {
            dealer.DoubleDownButton.gameObject.SetActive(false);
            dealer.SplitButton.gameObject.SetActive(false);
        }

        // Check if the Player busts, got to end hand.
        if (dealer.players[0].GetComponent <PlayerController>().Hand.Total > 21)
        {
            dealer.transform.Find("Table/GameStatusText").gameObject.GetComponent <Text>().text += dealer.players[0].name + " Busted!\n";
            if (PlayerController.Instance.NextHand())
            {
                ToDealerTurn();
                return;
            }
        }

        if (dealer.DoublingDown && PlayerController.Instance.NextHand())
        {
            ToDealerTurn();
            return;
        }

        dealer.DoublingDown = false;

        // Check if the Player stands
        if (dealer.PlayerStands)
        {
            dealer.PlayerStands = false;
            // If Next Hand is the first hand, move on.
            if (PlayerController.Instance.NextHand())
            {
                ToDealerTurn();
                return;
            }
        }
    }
Exemplo n.º 3
0
    public void UpdateState(float deltaTime)
    {
        if (FirstTime)
        {
            dealer.transform.Find("Table/GameStatusText").gameObject.GetComponent <Text>().text += "Press deal to begin\n";
            dealer.DealButton.gameObject.SetActive(true);
            dealer.PlayerStands     = false;
            dealer.Dealing          = false;
            dealer.DoublingDown     = false;
            dealer.Splitting        = false;
            dealer.BetField.enabled = true;
            dealer.RestoreBet();
            dealer.players[0].GetComponent <PlayerController>().UnSplitHand();
            FirstTime = false;
        }

        if (dealer.Dealing)
        {
            dealer.Restart();

            // Deal two cards to everyone
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < dealer.players.Count; j++)
                {
                    if (j == (dealer.players.Count - 1))
                    {
                        if (i == 1)
                        {
                            card = dealer.DealCard();
                        }
                        else
                        {
                            card = dealer.DealCard(false);
                        }
                    }
                    else
                    {
                        card = dealer.DealCard();
                    }

                    dealer.cardGameObjectMap[card].transform.SetParent(dealer.players[j].transform.FindChild("Table/Hand").transform);
                    dealer.players[j].GetComponent <PlayerController>().Hand.Add(card);
                    dealer.UpdateTotal(j);
                }
            }

            // Check if Dealer has a blackjack.
            if (dealer.HasBlackJack(dealer.DealerIndex))
            {
                dealer.UpdateBank();
                dealer.players[dealer.DealerIndex].GetComponent <PlayerController>().Hand.FlipUp();
                dealer.UpdateTotal(dealer.DealerIndex);
                dealer.transform.Find("Table/GameStatusText").gameObject.GetComponent <Text>().text = dealer.players[dealer.DealerIndex].name + " has Blackjack!\n";
                ToEndHand();
                return;
            }

            ToPlayerTurn();
        }
    }