Exemple #1
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());
            }
        }