예제 #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());
            }
        }
예제 #2
0
        public void buyHouse(Player player)
        {
            PlayerInput input = new PlayerInput();
            //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.getPropertiesOwnedFromBoard().Count == 0)
            {
                //write message
                Console.WriteLine("{0}You do not own any properties.", input.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.", input.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.", input.playerPrompt(player), propertyToBuyFor.getName(), Residential.getMaxHouses());
            }
            else
            {
                //confirm
                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());
                }
            }
        }
예제 #3
0
        public void tradeProperty(Player player)
        {
            PlayerInput input = new PlayerInput();
            Property property = new Property();
            //create prompt
            string sPropPrompt = String.Format("{0}Please select a property to trade:", input.playerPrompt(player));
            //create prompt
            string sPlayerPrompt = String.Format("{0}Please select a player to trade with:", input.playerPrompt(player));

            //get the property to trade
            //SMALL CHANGE WITH PROPERTY TEST AND SEE IF IT NEEDS TO GO BACK TO this.
            TradeableProperty propertyToTrade = (TradeableProperty)property.displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPropPrompt);

            //if dont own any properties
            if (propertyToTrade == null)
            {
                //write message
                Console.WriteLine("{0}You do not own any properties.", input.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?", input.playerPrompt(player));
            decimal amountWanted = input.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 = input.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}", input.playerPrompt(player), playerToTradeWith.getName(), propertyToTrade.getName(), amountWanted);
            }
        }