示例#1
0
        public void TradeProperty(Player player)
        {
            //create prompt
            string sPropPrompt = String.Format("{0}Please select a property to trade:", this.PlayerPrompt(player));
            //create prompt
            string sPlayerPrompt = String.Format("{0}Please select a player to trade with:", this.PlayerPrompt(player));

            //get the property to trade
            TradeableProperty propertyToTrade = (TradeableProperty)this.DisplayPropertyChooser(player.GetPropertiesOwnedFromBoard(), sPropPrompt);

            //if dont own any properties
            if (propertyToTrade == null)
            {
                //write message
                Console.WriteLine("{0}You do not own any properties.", PlayerPrompt(player));
                //return from method
                return;
            }

            //get the player wishing to trade with
            Player playerToTradeWith = this.DisplayPlayerChooser(Board.Access().GetPlayers(), player, sPlayerPrompt);

            //get the amount wanted

            string inputAmtMsg = string.Format("{0}How much do you want for this property?", PlayerPrompt(player));

            decimal amountWanted = InputDecimal(inputAmtMsg);

            //confirm with playerToTradeWith
            //set console color
            ConsoleColor origColor = Console.ForegroundColor;
            int          i         = Board.Access().GetPlayers().IndexOf(playerToTradeWith);

            Console.ForegroundColor = this._colors[i];

            bool agreesToTrade;
            var  mortgageInterest = Decimal.Zero;

            //get player response

            /*We need to do this to check and find if the property is mortgaged
             * and in the case that it is, notify the buyer that the price
             * of the property includes the original owner's mortgage interest*/
            if (propertyToTrade.GetType() == typeof(Residential))
            {
                var residentialPropertyToTrade = (Residential)propertyToTrade;

                if (residentialPropertyToTrade.IsMortgaged)
                {
                    mortgageInterest = residentialPropertyToTrade.GetMortgageValue() * 10 / 100;

                    agreesToTrade = GetInputYn(playerToTradeWith,
                                               string.Format(
                                                   "{0} wants to trade '{1}' with you for ${2} (including seller's mortgage interest for this property). Do you agree to pay {2} for '{1}'",
                                                   player.GetName(),                  /*{0}*/
                                                   propertyToTrade.GetName(),         /*{1}*/
                                                   amountWanted + mortgageInterest)); /*{2}*/
                }
                else // If it's not mortgaged do the normal trading behaviour
                {
                    agreesToTrade = GetInputYn(playerToTradeWith,
                                               string.Format("{0} wants to trade '{1}' with you for ${2}. Do you agree to pay {2} for '{1}'",
                                                             player.GetName(), propertyToTrade.GetName(), amountWanted));
                }
            }
            else
            {
                agreesToTrade = GetInputYn(playerToTradeWith,
                                           string.Format("{0} wants to trade '{1}' with you for ${2}. Do you agree to pay {2} for '{1}'",
                                                         player.GetName(), propertyToTrade.GetName(), amountWanted));
            }

            //resent console color
            Console.ForegroundColor = origColor;
            if (agreesToTrade)
            {
                Player playerFromBoard = Board.Access().GetPlayer(playerToTradeWith.GetName());
                //player trades property
                player.TradeProperty(ref propertyToTrade, ref playerFromBoard, amountWanted, mortgageInterest);
                Console.WriteLine("{0} has been traded successfully. {0} is now owned by {1}", propertyToTrade.GetName(), playerFromBoard.GetName());
            }
            else
            {
                //display rejection message
                Console.WriteLine("{0}{1} does not agree to trade {2} for ${3}", PlayerPrompt(player), playerToTradeWith.GetName(), propertyToTrade.GetName(), amountWanted);
            }
        }
示例#2
0
 public void PurchaseProperty(Player player, bool?testAnswer = null)
 {
     if (player.IsInJail)
     {
         Console.WriteLine("You are in Jail and can not purchase property.");
     }
     //if property available give option to purchase else so not available
     else if (Board.Access().GetProperty(player.GetLocation()).AvailableForPurchase())
     {
         TradeableProperty propertyLocatedOn = (TradeableProperty)Board.Access().GetProperty(player.GetLocation());
         bool?respYN = testAnswer ?? GetInputYn(player, string.Format("'{0}' is available to purchase for ${1}. Are you sure you want to purchase it?", propertyLocatedOn.GetName(), propertyLocatedOn.GetPrice()));
         if ((bool)respYN)
         {
             propertyLocatedOn.Purchase(ref player);//purchase property
             Console.WriteLine("{0}You have successfully purchased {1}.", PlayerPrompt(player), propertyLocatedOn.GetName());
         }
     }
     else
     {
         Console.WriteLine("{0}{1} is not available for purchase.", PlayerPrompt(player), Board.Access().GetProperty(player.GetLocation()).GetName());
     }
 }