Esempio n. 1
0
        public void SellHouse(Player player, Property testProperty = null)
        {
            var playersProperties = player.GetPropertiesOwnedFromBoard();

            if (playersProperties.Count == 0)
            {
                Console.WriteLine("{0}You do not own any properties.", PlayerPrompt(player));
                return;
            }

            // Get properties that are residential and have at least one house to be sold
            var developedResidentials =
                playersProperties.ToArray()
                .Where(x => x.GetType() == typeof(Residential))
                .Cast <Residential>()
                .Where(x => x.GetHouseCount() >= 1)
                .ToArray();

            if (!developedResidentials.Any())
            {
                Console.WriteLine("You don't have any properties with houses to be sold!");
                return;
            }

            // Add the correct propeties to an arraylist, this is because
            // the property chooser takes an arraylist not an IEnumarable
            var propertiesToChooseFrom = new ArrayList();

            propertiesToChooseFrom.AddRange(developedResidentials);

            var playerPrompt = String.Format("{0}Please select a property to sell the house for:", PlayerPrompt(player));

            // Get the property to buy house for
            var property = testProperty ?? DisplayPropertyChooser(propertiesToChooseFrom, playerPrompt);

            var propertyToSellHouse = (Residential)property;

            propertyToSellHouse.SellHouse();
            Console.WriteLine("House sold for ${0}", propertyToSellHouse.GetHouseCost() / 2);
        }
        public void MortgageOptions(Player player)
        {
            Console.WriteLine();
            Console.WriteLine("1. Mortgage property");
            Console.WriteLine("2. Pay mortgage on property");
            Console.WriteLine("3. Back to Main Menu");
            Console.Write("(1-3)>");

            //read response
            var resp = InputInteger();

            Residential property;
            switch (resp)
            {
                case 1:
                    property =
                        (Residential)
                            DisplayPropertyChooser(player.GetPropertiesOwnedFromBoard(), "Property to mortgage: ", true);
                    if (property == null)
                    {
                        Console.WriteLine("You don't own any properties!");
                    }
                    else if (property.MortgageProperty())
                    {
                        Console.WriteLine("Property has been mortgaged for {0}", property.GetMortgageValue());
                    }
                    else // If it wasn't mortgaged it must be developed or already be mortgaged
                    {
                        Console.WriteLine(
                            "Property can't be mortgaged. Either it is already mortgaged or has been developed.");
                    }
                    break;
                case 2:
                    property =
                        (Residential)
                            DisplayPropertyChooser(player.GetPropertiesOwnedFromBoard(), "Property to unmortgage: ",
                                true);

                    if (property == null)
                    {
                        Console.WriteLine("You don't own any properties!");
                    }
                    else if (property.UnmortgageProperty())
                    {
                        Console.WriteLine("Mortgage has been paid for property {0}", property.GetName());
                    }
                    else // If it wasn't unmortgaged it's because it wasn't mortgaged in the first place
                    {
                        Console.WriteLine("Property must be mortgaged for you to pay the mortgage");
                    }
                    break;
                case 3:
                    break;
                default:
                    Console.WriteLine("That option is not avaliable. Please try again.");
                    MortgageOptions(player);
                    break;
            }
        }
        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);
            }     
        }
        public void SellHouse(Player player, Property testProperty = null)
        {
            var playersProperties = player.GetPropertiesOwnedFromBoard();

            if (playersProperties.Count == 0)
            {
                Console.WriteLine("{0}You do not own any properties.", PlayerPrompt(player));
                return;
            }

            // Get properties that are residential and have at least one house to be sold
            var developedResidentials =
                playersProperties.ToArray()
                    .Where(x => x.GetType() == typeof (Residential))
                    .Cast<Residential>()
                    .Where(x => x.GetHouseCount() >= 1)
                    .ToArray();

            if (!developedResidentials.Any())
            {
                Console.WriteLine("You don't have any properties with houses to be sold!");
                return;
            }

            // Add the correct propeties to an arraylist, this is because
            // the property chooser takes an arraylist not an IEnumarable
            var propertiesToChooseFrom = new ArrayList();
            propertiesToChooseFrom.AddRange(developedResidentials);

            var playerPrompt = String.Format("{0}Please select a property to sell the house for:", PlayerPrompt(player));

            // Get the property to buy house for
            var property = testProperty ?? DisplayPropertyChooser(propertiesToChooseFrom, playerPrompt);

            var propertyToSellHouse = (Residential) property;

            propertyToSellHouse.SellHouse();
            Console.WriteLine("House sold for ${0}", propertyToSellHouse.GetHouseCost()/2);
        }
        public void BuyHouse(Player player, Property testProperty = null, bool? testAnswer = null)
        {
            if (Board.Access().Houses < 1)
            {
                Console.WriteLine("Sorry, the bank doesn't have any houses left.");
                return;
            }

            if (player.IsInJail)
            {
                Console.WriteLine("Sorry, you are in jail.");
                return;
            }

            //create prompt
            var sPrompt = String.Format("{0}Please select a property to buy a house for:", 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
            var property = testProperty ?? 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 not be bought for {1} because it is not a Residential Property.", this.PlayerPrompt(player), property.GetName());
                return;
            }

            if (propertyToBuyFor.IsMortgaged)
            {
                Console.WriteLine("{0}A house can not be bought for {1} because it is currently mortgaged.", PlayerPrompt(player), property.GetName());
                return;
            }
            
            // Player must own all the propeties in the colour group
            if (!player.OwnsAllPropertiesOfColour(propertyToBuyFor.GetHouseColour()))
            {
                Console.WriteLine(
                    "You must own all the properties within this colour group ({0}) to buy houses for this property.",
                    propertyToBuyFor.GetHouseColour());
                return;
            }

            // We've checked if they own the properties of the colour, now
            // check if each property is equally developed
            if (!player.CanDevelopPropertyFurther(propertyToBuyFor))
            {
                Console.WriteLine("Each property in this colour group needs to have houses uniformly added");
            }
            else if (propertyToBuyFor.HasHotel)// If it has a hotel they can't add more houses.
            {
                Console.WriteLine("This property has a hotel and can not be developed further.");
            }
            else
            {
                // Can't buy a fifth house if there are not hotels left
                if (propertyToBuyFor.GetHouseCount() == 4 && Board.Access().Hotels < 1)
                {
                    Console.WriteLine("You can't buy another house as this would result in a hotel and there aren't any hotels left.");
                    return;
                }

                //confirm
                var doBuyHouse = testAnswer ?? 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());
                }
            }
        }
Esempio n. 6
0
        public void MortgageOptions(Player player)
        {
            Console.WriteLine();
            Console.WriteLine("1. Mortgage property");
            Console.WriteLine("2. Pay mortgage on property");
            Console.WriteLine("3. Back to Main Menu");
            Console.Write("(1-3)>");

            //read response
            var resp = InputInteger();

            Residential property;

            switch (resp)
            {
            case 1:
                property =
                    (Residential)
                    DisplayPropertyChooser(player.GetPropertiesOwnedFromBoard(), "Property to mortgage: ", true);
                if (property == null)
                {
                    Console.WriteLine("You don't own any properties!");
                }
                else if (property.MortgageProperty())
                {
                    Console.WriteLine("Property has been mortgaged for {0}", property.GetMortgageValue());
                }
                else     // If it wasn't mortgaged it must be developed or already be mortgaged
                {
                    Console.WriteLine(
                        "Property can't be mortgaged. Either it is already mortgaged or has been developed.");
                }
                break;

            case 2:
                property =
                    (Residential)
                    DisplayPropertyChooser(player.GetPropertiesOwnedFromBoard(), "Property to unmortgage: ",
                                           true);

                if (property == null)
                {
                    Console.WriteLine("You don't own any properties!");
                }
                else if (property.UnmortgageProperty())
                {
                    Console.WriteLine("Mortgage has been paid for property {0}", property.GetName());
                }
                else     // If it wasn't unmortgaged it's because it wasn't mortgaged in the first place
                {
                    Console.WriteLine("Property must be mortgaged for you to pay the mortgage");
                }
                break;

            case 3:
                break;

            default:
                Console.WriteLine("That option is not avaliable. Please try again.");
                MortgageOptions(player);
                break;
            }
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
        public void BuyHouse(Player player, Property testProperty = null, bool?testAnswer = null)
        {
            if (Board.Access().Houses < 1)
            {
                Console.WriteLine("Sorry, the bank doesn't have any houses left.");
                return;
            }

            if (player.IsInJail)
            {
                Console.WriteLine("Sorry, you are in jail.");
                return;
            }

            //create prompt
            var sPrompt = String.Format("{0}Please select a property to buy a house for:", 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
            var property = testProperty ?? 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 not be bought for {1} because it is not a Residential Property.", this.PlayerPrompt(player), property.GetName());
                return;
            }

            if (propertyToBuyFor.IsMortgaged)
            {
                Console.WriteLine("{0}A house can not be bought for {1} because it is currently mortgaged.", PlayerPrompt(player), property.GetName());
                return;
            }

            // Player must own all the propeties in the colour group
            if (!player.OwnsAllPropertiesOfColour(propertyToBuyFor.GetHouseColour()))
            {
                Console.WriteLine(
                    "You must own all the properties within this colour group ({0}) to buy houses for this property.",
                    propertyToBuyFor.GetHouseColour());
                return;
            }

            // We've checked if they own the properties of the colour, now
            // check if each property is equally developed
            if (!player.CanDevelopPropertyFurther(propertyToBuyFor))
            {
                Console.WriteLine("Each property in this colour group needs to have houses uniformly added");
            }
            else if (propertyToBuyFor.HasHotel)// If it has a hotel they can't add more houses.
            {
                Console.WriteLine("This property has a hotel and can not be developed further.");
            }
            else
            {
                // Can't buy a fifth house if there are not hotels left
                if (propertyToBuyFor.GetHouseCount() == 4 && Board.Access().Hotels < 1)
                {
                    Console.WriteLine("You can't buy another house as this would result in a hotel and there aren't any hotels left.");
                    return;
                }

                //confirm
                var doBuyHouse = testAnswer ?? 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());
                }
            }
        }