public void buyHouse(Player player) { //create prompt string sPrompt = String.Format("{0}Please select a property to buy a house for:", this.playerPrompt(player)); //create variable for propertyToBuy Residential propertyToBuyFor = null; if (player.getPropertiesOwnedFromBoard().Count == 0) { //write message Console.WriteLine("{0}You do not own any properties.", playerPrompt(player)); //return from method return; } //get the property to buy house for Property property = this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt); //if dont own any properties //check that it is a residential if (property.GetType() == (new Residential().GetType())) { //cast to residential property propertyToBuyFor = (Residential)property; } else //else display msg { Console.WriteLine("{0}A house can no be bought for {1} because it is not a Residential Property.", this.playerPrompt(player), propertyToBuyFor.getName()); return; } //check that max houses has not been reached if (propertyToBuyFor.getHouseCount() >= Residential.getMaxHouses()) { Console.WriteLine("{0}The maximum house limit for {1} of {2} houses has been reached.", playerPrompt(player), propertyToBuyFor.getName(), Residential.getMaxHouses()); } else { //confirm bool doBuyHouse = this.getInputYN(player, String.Format("You chose to buy a house for {0}. Are you sure you want to purchase a house for ${1}?", propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost())); //if confirmed if (doBuyHouse) { //buy the house propertyToBuyFor.addHouse(); Console.WriteLine("{0}A new house for {1} has been bought successfully", playerPrompt(player), propertyToBuyFor.getName()); } } }
public void buyHouse(Player player) { //create prompt string sPrompt = String.Format("{0}Please select a property to buy a house for:", this.playerPrompt(player)); //create variable for propertyToBuy Residential propertyToBuyFor = null; if (player.getPropertiesOwnedFromBoard().Count == 0) { //write message Console.WriteLine("{0}\nYou do not own any properties.", playerPrompt(player)); //return from method return; } //get the property to buy house for Property property = this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt); //if dont own any properties //check that it is a residential if (property.GetType() == (new Residential().GetType())) { //cast to residential property propertyToBuyFor = (Residential)property; } else //else display msg { Console.WriteLine("{0}A house can no be bought for {1} because it is not a Residential Property.", this.playerPrompt(player), propertyToBuyFor.getName()); return; } //check that max houses has not been reached if (propertyToBuyFor.getHouseCount() >= Residential.getMaxHouses()) { Console.WriteLine("{0}The maximum house limit for {1} of {2} houses has been reached.", playerPrompt(player), propertyToBuyFor.getName(), Residential.getMaxHouses()); } else { //confirm bool doBuyHouse = this.getInputYN(player, String.Format("You chose to buy a house for {0}. Are you sure you want to purchase a house for ${1}?", propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost())); //if confirmed if (doBuyHouse) { //buy the house propertyToBuyFor.addHouse(); Console.WriteLine("{0}A new house for {1} has been bought successfully", playerPrompt(player), propertyToBuyFor.getName()); } } }
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); } }
/*----- METHOD TO UNMORTGAGE PROPERTY -----*/ public void unMortgageProperty(Player player) { string sPropPrompt = String.Format("{0}\tPlease select a property to mortgage:", this.playerPrompt(player)); //get selected property to UnMortgage TradeableProperty propertyToUnMortgage = (TradeableProperty)this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPropPrompt); //check if player has any mortgaged properties if (player.getPropertiesOwnedFromBoard().Count == 0) { Console.WriteLine("\n\tYou don't currently own any mortgaged properties."); } else { //now call the unmortgage method in Property class propertyToUnMortgage.unMortgage(propertyToUnMortgage); Console.WriteLine("\n\tYou've successfully unmortgaged " + propertyToUnMortgage.getName()); } }
/*----- METHOD TO MORTGAGE PROEPRTY -----*/ public void mortgageProperty(Player player) { decimal playerBalBeforeMortgage = player.getBalance(); string sPropPrompt = String.Format("{0}\tPlease select a property to mortgage:", this.playerPrompt(player)); //string sPlayerPrompt = String.Format("{0}\tPlease select a player to trade with:", this.playerPrompt(player)); //get selected property to mortgage TradeableProperty propertyToMortgage = (TradeableProperty)this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPropPrompt); //if dont own any properties if (player.getPropertiesOwnedFromBoard().Count == 0 /*propertyToMortgage == null*/) { //write message Console.WriteLine("\n{0}You do not own any properties to mortgage.", playerPrompt(player)); //return from method return; } decimal mortgageValue = propertyToMortgage.calculateMortgage(propertyToMortgage); Console.WriteLine("\tProperty you have chosen to mortgage is: " + propertyToMortgage.getName() + ", \tit's purchase price is $" + propertyToMortgage.getPrice()); Console.WriteLine("\n\tMortgage value is: " + mortgageValue); //check if property is already mortgaged if (propertyToMortgage.getMortgagedStatus() == false) { //make the bank pay the player mortgageValue Banker.access().pay(mortgageValue); //allocate mortgageValue to player player.receive(mortgageValue); Console.WriteLine("\n\tYour new balance is: " + player.getBalance()); propertyToMortgage.setPropertyIsMortgaged(); Console.WriteLine("\tyou've successfully mortaged " + propertyToMortgage.getName()); } else { Console.WriteLine("\n\t" + propertyToMortgage.getName() + " has already been mortgaged!"); } }
//Allow player to mortgage property public void mortgage_property(Player player) { string sPrompt = String.Format("{0}Please select a property to mortgage:", this.playerPrompt(player)); //Get the selected property to mortgage Property selected_property = this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt); if (player.getPropertiesOwnedFromBoard().Count == 0) { //write message Console.WriteLine("{0}You do not have any properties to mortgage! ", playerPrompt(player)); //return from method return; } if (selected_property.isMortgaged == true) { Console.WriteLine(selected_property.getName().ToString() + " has already been mortgaged! "); } else { decimal mortgage = selected_property.getMortgageValue(); selected_property.mortgageProperty(); Console.WriteLine("You have mortgaged" + selected_property.getName() + "and have been paid" + mortgage); } }