Exemplo n.º 1
0
        public void OnRaiseClicked()
        {
            Transform playerTransform = PlayersParent.transform.Find("Player" + CurrentPlayerIndex);
            Transform blindsTransform = playerTransform.Find("Blinds");

            PlayerWidget playerWidget = playerTransform.gameObject.GetComponent <PlayerWidget>();

            if (playerWidget == null)
            {
                Debug.LogError("GameController.OnRaiseClicked: PlayerWidget is null. Player index = " + CurrentPlayerIndex);
                return;
            }

            ChipAlignment chipAlignment = playerWidget.ChipAlignment;

            Hand   currentHand   = _currentGame.CurrentHand;
            Player currentPlayer = _currentGame.CurrentPlayer;

            int defaultAmountToRaise = Math.Min(currentHand.GetHighestBetNotInPot() * 2 - currentPlayer.CurrentBet, currentPlayer.ChipCount);
            int amountToRaise        = _currentAmountToBet > 0 ? _currentAmountToBet : defaultAmountToRaise;

            PutChipsInfrontPlayer(blindsTransform, amountToRaise, chipAlignment);

            DisplayPlayerActionText(CurrentPlayerIndex, TurnType.Raise, amountToRaise);

            if (OnPlayerTurnEnded != null)
            {
                OnPlayerTurnEnded(TurnType.Raise, amountToRaise);
            }
        }
Exemplo n.º 2
0
        public void OnBetClicked()
        {
            Transform playerTransform = PlayersParent.transform.Find("Player" + CurrentPlayerIndex);
            Transform blindsTransform = playerTransform.Find("Blinds");

            PlayerWidget playerWidget = playerTransform.gameObject.GetComponent <PlayerWidget>();

            if (playerWidget == null)
            {
                Debug.LogError("GameController.OnBetClicked: PlayerWidget is null. Player index = " + CurrentPlayerIndex);
                return;
            }

            ChipAlignment chipAlignment = playerWidget.ChipAlignment;

            int amountToBet = _currentAmountToBet > 0 ? _currentAmountToBet : _currentGame.BigBlindSize;

            PutChipsInfrontPlayer(blindsTransform, amountToBet, chipAlignment);

            DisplayPlayerActionText(CurrentPlayerIndex, TurnType.Bet, amountToBet);

            if (OnPlayerTurnEnded != null)
            {
                OnPlayerTurnEnded(TurnType.Bet, amountToBet);
            }
        }
Exemplo n.º 3
0
        private void PostPlayerBlind(int playerIndex, int blindSize)
        {
            Transform    playerTransform = PlayersParent.transform.Find("Player" + playerIndex);
            Transform    blindsTransform = playerTransform.Find("Blinds");
            PlayerWidget playerWidget    = playerTransform.gameObject.GetComponent <PlayerWidget>();

            if (playerWidget == null)
            {
                Debug.LogError("GameController.PostPlayerBlind: PlayerWidget is null. Player index = " + playerIndex);
                return;
            }

            ChipAlignment chipAlignment = playerWidget.ChipAlignment;

            PutChipsInfrontPlayer(blindsTransform, blindSize, chipAlignment);
        }
Exemplo n.º 4
0
        private void PutChipsInfrontPlayer(Transform place, int betAmount, ChipAlignment chipAlignment = ChipAlignment.Right)
        {
            if (chipAlignment == ChipAlignment.Invalid)
            {
                Debug.LogWarning("PutChipsInfrontPlayer: chipAlignment is invalid, applying right alignment.");
                chipAlignment = ChipAlignment.Right;
            }

            for (int chipDenominationIndex = _chipDenominations.Length - 1; chipDenominationIndex >= 0; chipDenominationIndex--)
            {
                int denomination = (int)_chipDenominations[chipDenominationIndex];
                if (denomination > betAmount)
                {
                    continue;
                }

                while (betAmount >= denomination)
                {
                    GameObject chipObject = GameObject.Instantiate(ChipPrefab);
                    ChipWidget chipWidget = chipObject.GetComponent <ChipWidget>();
                    chipWidget.Denomination = _chipDenominations[chipDenominationIndex];

                    Vector3 chipPosition = place.position;
                    int     chipsCount   = place.childCount;
                    if (chipsCount > 0)
                    {
                        int chipsInStack = chipsCount;
                        int stackIndex   = 0;
                        if (chipsCount >= Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS)
                        {
                            stackIndex   = chipsCount / Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS;
                            chipsInStack = chipsCount % Defines.MAX_CHIPS_IN_ONE_STACK_IN_BETS;
                        }
                        // TODO: correct this magic
                        if (stackIndex > 0)
                        {
                            if (chipAlignment == ChipAlignment.Right)
                            {
                                chipPosition.x += (chipWidget.ImageWidth * stackIndex);
                            }
                            else if (chipAlignment == ChipAlignment.Left)
                            {
                                chipPosition.x -= (chipWidget.ImageWidth * stackIndex);
                            }
                        }
                        chipPosition.y += (chipWidget.ImageHeight * chipsInStack) / 6;
                    }
                    chipObject.transform.parent = place;

                    chipObject.transform.localPosition = chipPosition;
                    chipObject.transform.localScale    = Vector3.one;

                    betAmount -= denomination;
                }
            }

            if (betAmount > 0)
            {
                Debug.LogError("PutChipsInfrontPlayer: wrong bet amount (could not be presented with current chip denominations).");
            }
        }