Exemplo n.º 1
0
    public static void EndOfRollOptions()
    {
        Tile       tile     = CurrentPlayer.Position;
        Property   property = tile.GetComponent <Property>();
        ChanceTile chance   = tile.GetComponent <ChanceTile>();
        //FreeParking parking = tile.GetComponent<FreeParking>();
        SandLTile    sAndL       = tile.GetComponent <SandLTile>();
        PaymentTile  paymentTile = tile.GetComponent <PaymentTile>();
        GoToJailTile goToJail    = tile.GetComponent <GoToJailTile>();

        if (property != null)
        {
            //check if the player stepped on an unowned/mortgaged/their own property
            if (property.Owner == null || property.Owner == CurrentPlayer || (property.Mortgaged && property.Owner != CurrentPlayer))
            {
                MenuManager.SwitchToMenuWithInventory(MenuManager.EndOfTurnOptions);
            }
            else
            {
                PlayerMustPay(property.PaymentPrice());
            }

            //display current property
            MenuManager.UpdateCardInfo(CurrentPlayer.Position.GetComponent <Property>());
        }
        else if (chance != null || sAndL != null)
        {
            if (chance != null)
            {
                _activeCard = ChanceDeck.DrawCard();
            }
            else if (sAndL != null)
            {
                if (UnityEngine.Random.Range(0f, 1f) < 0.5f)
                {
                    _activeCard = new Snake();
                }
                else
                {
                    _activeCard = new Ladder();
                }
            }

            //adds card to player's inventory
            CurrentPlayer.AddCard(ActiveCard);
            MenuManager.SwitchToMenuWithInventory(MenuManager.CardOptions);
            //pop up to show which card is drawn
            MenuManager.UpdateCardInfo(ActiveCard);
        }
        else if (paymentTile != null)
        {
            MenuManager.SwitchToMenuWithInventory(MenuManager.PaymentTileOptions);
        }
        else if (goToJail != null) // if on go to jail tile
        {
            //create new card, uses it, deletes it
            _activeCard = new CardMove("Go to Jail - Go directly to Jail - Do not pass Go, do not collect $200", EnumsForCards.cardMove.goToJail);
            CurrentPlayer.AddCard(ActiveCard);
            MenuManager.SwitchToMenuWithInventory(MenuManager.CardOptions);
            MenuManager.UpdateCardInfo(ActiveCard);
            ChanceDeck.DeleteLastCard();
        }
        else
        {
            MenuManager.SwitchToMenuWithInventory(MenuManager.EndOfTurnOptions);
        }
    }
Exemplo n.º 2
0
    //Funcitionality of all buttons relevant to an ongoing game. Their listeners are all placed
    //in this method as they can be called without pressing a button from the AI script.
    public static void CallIngameButtonListener(Button button)
    {
        Player player = GameManager.CurrentPlayer;

        if (player == null)
        {
            return;
        }

        bool ai = player.GetComponent <AI>();

        //Checks if ai called the listener or if the current player called it. This is needed
        //as if the player presses a button during the ai's turn, it needs to not do anything.
        if (button.interactable && ((!ai && ButtonClicked) || (ai && !ButtonClicked) ||
                                    /*only these buttons can be pressed by human when AI is active*/ button == Pay || button == TradingSystem.Offer || button == TradingSystem.Accept))
        {
            if (button == Roll)
            {
                Die.Roll();
            }
            else if (button == Buy)
            {
                GameManager.CurrentPlayer.Purchase();
                GameManager.UpdateBuyButtonInteractibility();
                GameManager.UpdateAuctionButtonInteractibility();
                GameManager.UpdateNextPlayerButtonInteractibility();
                UpdateInventoryData();
            }
            else if (button == PayFixed)
            {
                GameManager.PlayerMustPay(200);
            }
            else if (button == PayPercentage)
            {
                GameManager.PlayerMustPay((ushort)(0.1 * GameManager.CurrentPlayer.GetTotalPotentialBalance()));
            }
            else if (button == Pay)
            {
                Property    property    = GameManager.CurrentPlayer.Position.GetComponent <Property>();
                ChanceTile  chance      = GameManager.CurrentPlayer.Position.GetComponent <ChanceTile>();
                PaymentTile paymentTile = GameManager.CurrentPlayer.Position.GetComponent <PaymentTile>();
                if (property != null)
                {
                    ushort payment = property.PaymentPrice();
                    GameManager.CurrentPlayer.RemoveFunds(payment);
                    property.Owner.AddFunds(payment);
                    SwitchToMenuWithInventory(EndOfTurnOptions);
                }
                else if (chance != null)
                {
                    if (GameManager.ActiveCard is CardCollect)
                    {
                        ushort payment = 50;
                        CardCollect.currentPayee.RemoveFunds(payment);
                        GameManager.CurrentPlayer.AddFunds(payment);
                        CardCollect.currentPayee = GameManager.Players[(Array.IndexOf(GameManager.Players, CardCollect.currentPayee) + 1) % GameManager.Players.Length];

                        //switches payment to next player
                        if (CardCollect.currentPayee != GameManager.CurrentPlayer)
                        {
                            GameManager.PlayerMustPay(payment, CardCollect.currentPayee);
                        }
                        //if looped back around to current player, stop payment loop
                        else
                        {
                            SwitchToMenuWithInventory(EndOfTurnOptions);
                        }

                        //moves camera to whomever needs to pay
                        CameraFollow.target = CardCollect.currentPayee.transform;
                    }
                    else if (GameManager.ActiveCard is CardPay)
                    {
                        CardPay activeCard = (CardPay)GameManager.ActiveCard;
                        ushort  payment    = GameManager.PaymentNeeded;
                        GameManager.CurrentPlayer.RemoveFunds(payment);
                        CardPay cardPay = (CardPay)GameManager.ActiveCard;

                        //if statement to check player still exists
                        if (cardPay.Type == EnumsForCards.cardPay.payEachPlayer)
                        {
                            //Pays amount to each player
                            foreach (Player p in GameManager.Players)
                            {
                                if (p != GameManager.CurrentPlayer)
                                {
                                    p.AddFunds(activeCard.Amount);
                                }
                            }
                        }
                        SwitchToMenuWithInventory(EndOfTurnOptions);
                    }
                }
                else if (paymentTile != null)
                {
                    ushort payment = GameManager.PaymentNeeded;
                    GameManager.CurrentPlayer.RemoveFunds(payment);
                    SwitchToMenuWithInventory(EndOfTurnOptions);
                }
            }
            else if (button == AcknowledgeCard)
            {
                SwitchToMenuWithInventory(EndOfTurnOptions);
                if (!(GameManager.ActiveCard is CardGetOutOfJail || GameManager.ActiveCard is TileLink))
                {
                    GameManager.ActiveCard.Use();
                }
                UpdateInventoryData();
            }
            else if (button == Auction)
            {
                Auction.interactable = false;
                GameManager.UpdateBuyButtonInteractibility();
                GameManager.UpdateNextPlayerButtonInteractibility();                                                   //update this when Trading System is implemented
                AuctionSystem.StartAuction();
            }
            else if (button == NextTurn)
            {
                GameManager.NextPlayer();
            }
            else if (button == Bankrupt)
            {
                //remove all properties and cards from player
                Player lostPlayer = GameManager.CurrentPlayer;
                lostPlayer.Reset();
                GameManager.NextPlayer();
                GameManager.RemoveActivePlayer(lostPlayer);
            }
            else if (button == BuildHouse)
            {
                _houseMode = !_houseMode;
                if (_houseMode)
                {
                    Roll.interactable  = false;
                    Trade.interactable = false;
                    BuildHouse.GetComponentInChildren <Text>().text = "Back";
                }
                else
                {
                    Roll.interactable  = true;
                    Trade.interactable = true;
                    BuildHouse.GetComponentInChildren <Text>().text = "Build House";
                }
                UpdateInventoryData();
            }
            else if (button == BackToNormalCamera)
            {
                SwitchToMenuWithInventory(TurnOptions);
                SwitchToCamera(!GameManager.OnlyAIsInGame ? MainCamera : AmbientCamera);
            }
            else if (button == Trade)
            {
                TradingSystem.ShowTradingOptions();
            }
            //go to TradingSystem class if button is part of the trading system
            else if (Array.IndexOf(TradingSystem.Buttons, button) != -1)
            {
                TradingSystem.CallTradingButtonListener(button);
            }
            else if (button == PayToLeaveJail)
            {
                GameManager.PlayerMustPay(50);
                Jail.LeaveJail();
                SwitchToMenuWithInventory(EndOfTurnOptions);
            }
        }

        _buttonClicked = false;
    }