예제 #1
0
        //Action that is performed when a player lands on a railroad space.
        //If no one owns this railroad, the player is prompt if they want to buy it
        //else If the space is owned and the player can pay the owner, they can continue playing.
        //Else they cannot pay the owner, they are bankrupt
        private void RailroadSpaceAction(RailroadSpace rSpace)
        {
            if (rSpace.GetOwner() == null && DoesPlayerHaveMoney(rSpace.GetRailroad()))
            {
                if (MessageBox.Show("This is a railroad space - " + rSpace.GetRailroad().GetName() + ", Cost - " + rSpace.GetRailroad().GetCost().ToString("C2"),
                                    "Buy?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    railroadsOwned.Add(rSpace.GetRailroad());
                    RemoveMoney(rSpace.GetRailroad());
                    rSpace.SetOwner(this);
                }
            }
            else if (rSpace.GetOwner() != null && DoesPlayerHaveMoney(rSpace.GetRailroad().GetCost() * GetNumOfRailroadsOwned()))
            {
                Player spaceOwner = (Player)rSpace.GetOwner();
                int    payment    = rSpace.GetRailroad().GetCost() * spaceOwner.GetNumOfRailroadsOwned();

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

                spaceOwner.AddMoney(this.RemoveMoneyWithReturn(payment));
            }
            else if (rSpace.GetOwner() != null)
            {
                Player spaceOwner = (Player)rSpace.GetOwner();

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

                TradeAllAssets(spaceOwner);
            }
        }
예제 #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();
        }