示例#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];

            //get player response
            bool 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);
                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)
 {
     //if property available give option to purchase else so not available
     if (Board.access().getProperty(player.getLocation()).availableForPurchase())
     {
         TradeableProperty propertyLocatedOn = (TradeableProperty)Board.access().getProperty(player.getLocation());
         bool respYN = getInputYN(player, string.Format("'{0}' is available to purchase for ${1}. Are you sure you want to purchase it?", propertyLocatedOn.getName(), propertyLocatedOn.getPrice()));
         if (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());
     }
 }
示例#3
0
 public void tradeProperty(ref TradeableProperty property, ref Player purchaser, decimal amount)
 {
     purchaser.pay(amount);
     this.receive(amount);
     property.setOwner(ref purchaser);
 }
示例#4
0
 public void tradeProperty(ref TradeableProperty property, ref Player purchaser, decimal amount)
 {
     purchaser.pay(amount);
     this.receive(amount);
     property.setOwner(ref purchaser);
 }
示例#5
0
        public void tradeProperty(ref TradeableProperty property, ref Player purchaser, decimal amount)
        {
            //get property's original mortgage price
            decimal originalMortgagePrice = property.calculateMortgage(property);
            //get 10% of original mortgage price
            decimal originalMortgagePriceTenPercent = originalMortgagePrice * 10 / 100;
            decimal unMortgagePrice = originalMortgagePrice + originalMortgagePriceTenPercent;

            //purchaser.pay(amount);

            //check if purchased property is already mortgaged
            if (property.getMortgagedStatus() == true)
            {
                int userOption = 0;
                //if purchased property is mortgaged then player must unmortgage
                Console.WriteLine("\n\tThis property is currently mortgaged, you must either:\n\t1. Unmortgage it for the mortgage price plus 10%.\n\t2. Pay the bank 10% and keep it mortgaged.\n");

                //get user options input
                userOption = userInput();

                //grab user input value and run appropriate methods
                try
                {
                    switch (userOption)
                    {
                        case 1:
                            purchaser.pay(unMortgagePrice);
                            //---STILL NEED TO MAKE OTHER PLAYER RECEIVE PAYMENT
                            this.receive(unMortgagePrice);
                            property.setPropertyNotMortgaged();
                            property.setOwner(ref purchaser);
                            //property.unMortgage(property);
                            //Console.WriteLine("You've unmortgaged this property and now own it");
                            break;
                        case 2:
                            //pay 10%
                            purchaser.pay(originalMortgagePriceTenPercent);
                            //allocate da moneys to da banker
                            Banker.access().receive(originalMortgagePriceTenPercent);
                            //keep property as mortgaged
                            property.setPropertyIsMortgaged();

                            property.getMortgagedStatus();
                            //set owner
                            property.setOwner(ref purchaser);
                            break;
                    }
                }
                catch (ApplicationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                this.receive(amount);
                property.setOwner(ref purchaser);
            }
        }