public void buyHouse(Player player)
        {
            //Create prompt
            string sPrompt = String.Format("{0}Please select a property to buy a house for:"
                , input.playerPrompt(player));
            //Create variable for propertyToBuy
            Residential propertyToBuyFor = null;
            //If player doesn't own any properties, display message and return
            if (player.getPropertiesOwnedFromBoard().Count == 0)
            {
                Console.WriteLine("{0}You do not own any properties.", input.playerPrompt(player));
                return;
            }
            //Get the property to buy house
            Property property = this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt);
            //If user doesn't own any properties

            //Check that it is a residential if not display message
            if (property.GetType() == (new Residential().GetType()))
            {
                //cast to residential property
                propertyToBuyFor = (Residential)property;
            }
            else
            {
                Console.WriteLine("{0}A house can't be bought for {1} because it is not a Residential Property."
                    , input.playerPrompt(player), propertyToBuyFor.getName());
                return;
            }

            //Checks 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."
                    , input.playerPrompt(player), propertyToBuyFor.getName(), Residential.getMaxHouses());
            }
            else
            {
                bool doBuyHouse = input.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 (doBuyHouse)
                {
                    //buy the house
                    propertyToBuyFor.addHouse();
                    Console.WriteLine("{0}A new house for {1} has been bought successfully"
                        , input.playerPrompt(player), propertyToBuyFor.getName());
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Brown"))
                {
                    //confirm
                    if (player.getBrownOwned() == 2)
                    {
                        bool dobuyHouse = input.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", input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Cyan"))
                {
                    //confirm
                    if (player.getCyanOwned() == 3)
                    {
                        bool dobuyHouse = input.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", input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Purple"))
                {
                    //confirm
                    if (player.getPurpleOwned() == 3)
                    {
                        bool dobuyHouse = input.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", input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Orange"))
                {
                    //confirm
                    if (player.getOrangeOwned() == 3)
                    {
                        bool dobuyHouse = input.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", input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Orange"))
                {
                    //confirm
                    if (player.getOrangeOwned() == 4)
                    {
                        bool dobuyHouse = input.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"
                                , input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Yellow"))
                {
                    //confirm
                    if (player.getYellowOwned() == 4)
                    {
                        bool dobuyHouse = input.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", input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Red"))
                {
                    //confirm
                    if (player.getRedOwned() == 3)
                    {
                        bool dobuyHouse = input.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", input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Green"))
                {
                    //confirm
                    if (player.getGreenOwned() == 3)
                    {
                        bool dobuyHouse = input.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"
                                , input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
                else if ((propertyToBuyFor.getHouseCount() < Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Blue"))
                {
                    //confirm
                    if (player.getBlueOwned() == 2)
                    {
                        bool dobuyHouse = input.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"
                                , input.playerPrompt(player), propertyToBuyFor.getName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} You may not purchase houses until you own all properties of this colour group."
                            , input.playerPrompt(player));
                    }
                }
            }
        }
Exemple #2
0
        public void purchaseProperty(Player player)
        {
            PlayerInput input = new PlayerInput();
            //if property available give option to purchase else say not available
            if (Board.access().getProperty(player.getLocation()).availableForPurchase())
            {
                TradeableProperty propertyLocatedOn = (TradeableProperty)Board.access().getProperty(player.getLocation());
                try
                {
                    Residential purchasedProperty = (Residential)Board.access().getProperty(player.getLocation());
                    bool respYN = input.getInputYN(player, string.Format("'{0}' ({1}) is available to purchase for ${2}. Are you sure you want to purchase it?",
                        propertyLocatedOn.getName(), purchasedProperty.getGroupColours(), propertyLocatedOn.getPrice()));
                    if (respYN)
                    {
                        propertyLocatedOn.purchase(ref player);//purchase property
                        Console.WriteLine("{0}You have successfully purchased {1}.", input.playerPrompt(player), propertyLocatedOn.getName());

                        // Series of checks to determine the property's colour group and increment player's total owned for that group
                        if (purchasedProperty.getGroupColours() == "Brown")
                        {
                            int newTotal = player.getBrownOwned() + 1;
                            player.setBrownOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Cyan")
                        {
                            int newTotal = player.getCyanOwned() + 1;
                            player.setCyanOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Purple")
                        {
                            int newTotal = player.getPurpleOwned() + 1;
                            player.setPurpleOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Orange")
                        {
                            int newTotal = player.getOrangeOwned() + 1;
                            player.setOrangeOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Yellow")
                        {
                            int newTotal = player.getYellowOwned() + 1;
                            player.setYellowOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Red")
                        {
                            int newTotal = player.getRedOwned() + 1;
                            player.setRedOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Green")
                        {
                            int newTotal = player.getGreenOwned() + 1;
                            player.setGreenOwned(newTotal);
                        }
                        else if (purchasedProperty.getGroupColours() == "Blue")
                        {
                            int newTotal = player.getBlueOwned() + 1;
                            player.setBlueOwned(newTotal);
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    if (propertyLocatedOn is Utility)
                    {
                        Utility purchasedProperty = (Utility)Board.access().getProperty(player.getLocation());
                        bool respYN = input.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}.", input.playerPrompt(player), propertyLocatedOn.getName());
                        }
                    }
                    else if (propertyLocatedOn is Transport)
                    {
                        Transport purchasedProperty = (Transport)Board.access().getProperty(player.getLocation());
                        bool respYN = input.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}.", input.playerPrompt(player), propertyLocatedOn.getName());
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("{0}{1} is not available for purchase.", input.playerPrompt(player), Board.access().getProperty(player.getLocation()).getName());
            }
        }
        //Allows players to buy a hotel for its colourGroup
        public void buyHotel(Player player)
        {
            string sPrompt = String.Format("{0}Please select a property to buy a hotel for:"
                , input.playerPrompt(player));

            Residential propertyToBuyFor = null;
            //If players don't own properties method returns
            if (player.getPropertiesOwnedFromBoard().Count == 0)
            {
                Console.WriteLine("{0}You do not own any properties."
                    , input.playerPrompt(player));
                return;
            }

            //Gets the property to buy house for
            Property property = this.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt);

            if (property.GetType() == (new Residential().GetType()))
            {
                propertyToBuyFor = (Residential)property;
            }
            else
            {
                Console.WriteLine("{0}A hotel can not be bought for {1} because it is not a Residential Property."
                    , input.playerPrompt(player), property.getName());
                return;
            }

            //check that max houses has been reached
            if (propertyToBuyFor.getHouseCount() != Residential.getMaxHouses())
            {
                Console.WriteLine("{0}You must own the maximum number of houses on a property to add a hotel."
                    , input.playerPrompt(player));
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Brown"))
            {
                if (player.getBrownOwned() == 2)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully", input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group.", input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Cyan"))
            {
                if (player.getCyanOwned() == 3)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully", input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group.", input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Purple"))
            {
                if (player.getPurpleOwned() == 3)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully", input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group.", input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Orange"))
            {
                if (player.getOrangeOwned() == 4)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully"
                            , input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group."
                        , input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Yellow"))
            {
                if (player.getYellowOwned() == 4)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully"
                            , input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group."
                        , input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Red"))
            {
                if (player.getRedOwned() == 4)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully", input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group.", input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Green"))
            {
                if (player.getGreenOwned() == 4)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully", input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group.", input.playerPrompt(player));
                }
            }
            else if ((propertyToBuyFor.getHouseCount() == Residential.getMaxHouses()) && (propertyToBuyFor.getGroupColours() == "Blue"))
            {
                if (player.getBlueOwned() == 4)
                {
                    bool doBuyHotel = input.getInputYN(player, String.Format("You chose to buy a hotel for {0}. Are you sure you want to purchase a hotel for ${1}?"
                        , propertyToBuyFor.getName(), propertyToBuyFor.getHouseCost()));
                    if (doBuyHotel)
                    {
                        propertyToBuyFor.addHotel();
                        Console.WriteLine("{0}A new hotel for {1} has been bought successfully", input.playerPrompt(player), propertyToBuyFor.getName());
                    }
                }
                else
                {
                    Console.WriteLine("{0} You may not purchase hotels til you own all properties of this colour group.", input.playerPrompt(player));
                }
            }
        }