コード例 #1
0
        //Action that is performed when a player lands on a property space.
        //Allows the owner of the space to upgrade the space when landed on.
        //Other players have to pay rent and if they cannot, they become bankrupt.
        //If no one owns the space, the player can purchase it.
        private void PropertySpaceAction(PropertySpace pSpace)
        {
            if (pSpace.GetOwner() == null && DoesPlayerHaveMoney(pSpace.GetProperty()))
            {
                if (MessageBox.Show("Would you like to buy - " + pSpace.GetProperty().GetPropertyName() + ", Cost - " + pSpace.GetProperty().GetPropertyCost().ToString("C2"),
                                    "Buy?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    propertysOwned.Add(pSpace.GetProperty());
                    RemoveMoney(pSpace.GetProperty());
                    pSpace.SetOwner(this);
                }
            }
            else if (pSpace.GetOwner() == null && !DoesPlayerHaveMoney(pSpace.GetProperty()))
            {
                MessageBox.Show("Cannot afford " + pSpace.GetProperty().GetPropertyName());
            }
            else if (pSpace.GetOwner() == this && pSpace.GetProperty().GetNumOfHouses() < 5 && DoesPlayerHaveMoney(pSpace.GetProperty().GetUpgradeCost()))
            {
                if (MessageBox.Show("Would you like to upgrade  " + pSpace.GetProperty().GetPropertyName() + ", Cost - " + pSpace.GetProperty().GetPropertyCost().ToString("C2"),
                                    "Upgrade?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    pSpace.GetProperty().IncreaseNumOfHouses();
                    RemoveMoney(pSpace.GetProperty().GetUpgradeCost());
                }
            }
            else if (pSpace.GetOwner() == this && pSpace.GetProperty().GetNumOfHouses() == 5)
            {
                MessageBox.Show(pSpace.GetProperty().GetPropertyName() + " is fully upgraded", "WHOA", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (pSpace.GetOwner() != null && DoesPlayerHaveMoney(pSpace.GetProperty().CalculatePayment()))
            {
                int    payment    = pSpace.GetProperty().CalculatePayment();
                Player spaceOwner = (Player)pSpace.GetOwner();

                MessageBox.Show("Player " + spaceOwner.GetPlayerId() + " owns this property. You paid them " +
                                payment.ToString("C2") + " in rent");

                spaceOwner.AddMoney(this.RemoveMoneyWithReturn(payment));
            }
            else if (pSpace.GetOwner() != null && !DoesPlayerHaveMoney(pSpace.GetProperty().CalculatePayment()))
            {
                Player spaceOwner = (Player)pSpace.GetOwner();

                MessageBox.Show("Player " + spaceOwner.GetPlayerId() + " owns this property. You cannot pay and have declared bankruptcy");
                BankruptPlayer();

                TradeAllAssets(spaceOwner);
            }
            else
            {
                MessageBox.Show("If this happens, it's broke.");
            }
        }
コード例 #2
0
        //Method that is used to determine what the player action should be.
        //Method depends heavliy on what space is sent over.
        public void Action(Space space, GameBoard board, List <Player> players)
        {
            if (space is PropertySpace)
            {
                PropertySpace temp = (PropertySpace)space;
                PropertySpaceAction(temp);
            }
            else if (space is ChanceSpace)
            {
                //Player draws a chance card and the card effect is applied
                ChanceCards card = ChanceSpace.DrawCard();
                MessageBox.Show(card.GetChanceDescription());
                card.CardEffect(this, board, card, players);

                //Activates the property space action when player is moved to a property space.
                if (card.GetChanceEffect() == 2 || card.GetChanceEffect() == 3 || card.GetChanceEffect() == 13 || card.GetChanceEffect() == 12)
                {
                    PropertySpace temp = (PropertySpace)GetSpaceOccupied();
                    PropertySpaceAction(temp);
                }
            }
            else if (space is CommunityChestSpace)
            {
                //Player draws a community chest card and the card effect is applied
                CommunuityChestCards card = CommunityChestSpace.DrawCard();
                MessageBox.Show(card.GetCommunuityChestName());
                card.CardEffect(this, card);
            }
            else if (space is UtilitySpace)
            {
                UtilityAction(space);
            }
            else if (space is FreeParkingSpace)
            {
                //Gives player who landed on free parking the total money given to free parking.
                FreeParkingSpace fpSpace = (FreeParkingSpace)space;
                MessageBox.Show($"Player {playerId} has collect {fpSpace.GetAccumulatedMoney().ToString("C2")}");
                fpSpace.CollectMoney(this);
            }
            else if (space is RailroadSpace)
            {
                RailroadSpace temp = (RailroadSpace)space;
                RailroadSpaceAction(temp);
            }
            else if (space is GoToJailSpace)
            {
                //Sends player to jail space and jails them
                MessageBox.Show("Sent to Jail");
                MovePlayerToSpace(board.GetJailSpace());
                JailSpace jailSpace = (JailSpace)spaceOccupied;

                if (!isJailed)
                {
                    jailSpace.AddPlayerToJail(this);
                }
                else
                {
                    jailSpace.EscapeJail(this);
                }
            }
            else if (space is JailSpace || IsPlayerJailed() == true)
            {
                //If player is jailed, it allows them to attempt escape or if they
                //have a get out of jail free card, they can instantly escape.
                JailSpace jailSpace = (JailSpace)board.GetJailSpace();

                if (HasGetOutOfJailFreeCard())
                {
                    jailSpace.RemovePlayerFromJail(this);
                }

                if (isJailed)
                {
                    jailSpace.EscapeJail(this);
                }
            }

            CheckForLost();
        }