示例#1
0
        public void TestIntInputCorrectlyParsesWithValidIntInput()
        {
            PlayerInput input = new PlayerInput();

            int testInt = 2;
            Assert.AreEqual(2, testInt);
        }
示例#2
0
        public void PlayerPromptCorrectlyDisplaysPromptWithPlayerName()
        {
            //Board board = new Board();
            Player player = new Player("Player 1:");
            //board.AddPlayer(player);
            Board.access().addPlayer(player);
            PlayerInput input = new PlayerInput();

            String testPrompt = input.playerPrompt(1);

            Assert.That(testPrompt, Is.StringContaining("Player 1:"));
        }
示例#3
0
        public void displayMainMenu()
        {
            PlayerInput input = new PlayerInput();
            int resp = 0;
            Console.WriteLine("Welcome to Monopoly Console Game\n\n");
            Console.WriteLine("Please make a selection:\n");
            Console.WriteLine("1. Setup Monopoly Game");
            Console.WriteLine("2. Start New Game");
            Console.WriteLine("3. Load Game");
            Console.WriteLine("4. Exit");
            Console.Write("(1-4)>");
            //read response
            resp = input.inputInteger();
            //if response is invalid redisplay menu
            if (resp == 0)
                this.displayMainMenu();

            //perform choice according to number input
            try
            {
                switch (resp)
                {
                    case 1:
                        this.setUpGame();
                        this.gameSetUp = true;
                        this.displayMainMenu();
                        break;
                    case 2:
                        if (this.gameSetUp)
                            this.playGame();
                        else
                        {
                            Console.WriteLine("\nThe Game has not been set up yet.\n");
                            this.displayMainMenu();
                        }
                        break;
                    case 3:
                        throw new ApplicationException("\nThis option is not avaliable yet\n");
                    case 4:
                        Environment.Exit(0);
                        break;
                    default:
                        throw new ApplicationException("\nThat option is not avaliable. Please try again.\n");
                }
            }
            catch (ApplicationException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#4
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());
                }
            }
        }
示例#5
0
        public Property displayPropertyChooser(ArrayList properties, String sPrompt)
        {
            PlayerInput input = new PlayerInput();

            //if no properties return null
            if (properties.Count == 0)
                return null;
            Console.WriteLine(sPrompt);
            for (int i = 0; i < properties.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, properties[i].ToString());
            }
            //display prompt
            Console.Write("({0}-{1})>", 1, properties.Count);
            //get input
            int resp = input.inputInteger();

            //if outside of range
            if ((resp < 1) || (resp > properties.Count))
            {
                Console.WriteLine("That option is not avaliable. Please try again.");
                this.displayPropertyChooser(properties, sPrompt);
                return null;
            }
            else
            {
                //return the appropriate property
                return (Property)properties[resp - 1];
            }
        }
示例#6
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());
            }
        }
示例#7
0
        public void mortgageProperty(Player player)
        {
            PlayerInput input = new PlayerInput();
            Monopoly game = new Monopoly();
            // Checks if player owns any properties
            if (player.getPropertiesOwnedFromBoard().Count == 0)
            {
                //write message
                Console.WriteLine("{0}You do not own any properties.", input.playerPrompt(player));
                //return from method
                return;
            }
            //create prompt
            string sPrompt = String.Format("{0}Please select a property to mortgage:", input.playerPrompt(player));

            // Check that it is a residential
            // If a property is residential, any hotels or houses on the property will be mortgaged before the property itself is mortgaged
            Property property = displayPropertyChooser(player.getPropertiesOwnedFromBoard(), sPrompt);
            if (property.GetType() == (new Residential().GetType()))
            {
                //create variable for propertyToMortgage
                Residential propertyToMortgage = (Residential)property;

                if (propertyToMortgage.getHotelCount() > 0)
                {
                    Console.WriteLine("Mortgaging the hotel on {0}", propertyToMortgage.getName());
                    propertyToMortgage.setHotelCount(propertyToMortgage.getHotelCount() - 1);
                    player.receive(propertyToMortgage.getHotelCost() / 2);
                }
                else if ((propertyToMortgage.getHouseCount() > 0) && (propertyToMortgage.getHotelCount() == 0))
                {
                    Console.WriteLine("Mortgaging a house on {0}", propertyToMortgage.getName());
                    propertyToMortgage.setHouseCount(propertyToMortgage.getHouseCount() - 1);
                    player.receive(propertyToMortgage.getHouseCost() / 2);
                }
                else
                {
                    Console.WriteLine("Mortgaging property {0}", propertyToMortgage.getName());
                    player.receive(propertyToMortgage.getPrice() / 2);
                    propertyToMortgage.setMortgaged(true);
                }
            }
        }
示例#8
0
        public void displayJailMenu(Player player)
        {
            Monopoly game = new Monopoly();
            Property property = new Property();
            TradeableProperty trade = new TradeableProperty();
            PlayerInput input = new PlayerInput();

            // If the player has been in Jail for 3 turns, on the 4th turn in jail they will be forced to pay themselves out
            if (player.getTurnsInJail() < 3)
            {
                int resp = 0;
                Console.WriteLine("1. Roll doubles to get out of jail");
                Console.WriteLine("2. Pay $50 to get out of jail");
                Console.WriteLine("3. Use \"Get out of jail free\" card");
                Console.WriteLine("4. Trade Property with Player");
                Console.WriteLine("5. Upgrade properties");
                Console.WriteLine("6. View your details");
                Console.WriteLine("7. Declare Bankrupt");
                Console.Write("(1-7)>");
                //read response
                resp = input.inputInteger();
                //if response is invalid redisplay menu
                if (resp == 0)
                    this.displayJailMenu(player);

                //perform choice according to number input
                switch (resp)
                {
                    case 1:
                        player.playerJailRoll();
                        break;
                    case 2:
                        if (player.getBalance() >= 50)
                        {
                            player.pay(50);
                            Console.WriteLine("{0} payed $50 to get out of jail.\n", player.getName());
                            player.setSentToJail(false);
                            player.setInJail(false);
                            player.setTurnsInJail(0);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("You do not have enough money, please make another selection.\n");
                            this.displayJailMenu(player);
                            break;
                        }
                    case 3:
                        if (player.getGetOutOfJailCard())
                        {
                            Console.WriteLine("{0} used their get out of Jail card.\n", player.getName()); ;
                            player.setGetOutOfJailCard(false);
                            player.setInJail(false);
                            player.setTurnsInJail(0);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("{0} doesn't have a get out of Jail card, please make another selection.\n", player.getName());
                            this.displayJailMenu(player);
                            break;
                        }
                    case 4:
                        game.tradeProperty(player);
                        displayJailMenu(player);
                        break;
                    case 5:
                        Console.WriteLine("That option is not implemented yet, please try again.\n");
                        break;
                    case 6:
                        Console.WriteLine("==================================");
                        Console.WriteLine(player.FullDetailsToString());
                        Console.WriteLine("==================================");
                        this.displayJailMenu(player);
                        break;
                    case 7:
                        Console.WriteLine("That option is not implemented yet, please try again.\n");
                        break;
                    default:
                        Console.WriteLine("That option is not avaliable, please try again.");
                        this.displayJailMenu(player);
                        break;
                }
                player.setTurnsInJail(player.getTurnsInJail() + 1);
            }

            // Runs on player's 4th turn in jail
            else if (player.getTurnsInJail() == 3)
            {
                Console.WriteLine("{0} has been in jail for 3 turns and must pay the $50", player.getName());
                player.setInJail(false);
                player.setSentToJail(false);
                player.pay(50);
                player.setTurnsInJail(0);
            }
        }
示例#9
0
        public void displayGameMenu(Player player)
        {
            int resp = 0;
            Monopoly game = new Monopoly();
            PlayerInput input = new PlayerInput();
            Property property = new Property();
            UpgradeProperties upgrade = new UpgradeProperties();

            Console.WriteLine("\n{0}Please make a selection:\n", input.playerPrompt(player));
            Console.WriteLine("1. Finish turn");
            Console.WriteLine("2. View your details");
            Console.WriteLine("3. Purchase This Property");
            Console.WriteLine("4. Buy House for Property");
            Console.WriteLine("5. Buy Hotel for Property");
            Console.WriteLine("6. Trade Property with Player");
            Console.WriteLine("7. Mortgage a property");
            Console.WriteLine("8. Declare Bankrupt");
            Console.WriteLine("9. Quit Game");
            Console.Write("(1-9)>");
            //read response
            resp = input.inputInteger();
            //if response is invalid redisplay menu
            if (resp == 0)
                this.displayGameMenu(player);

            //perform choice according to number input
            switch (resp)
            {
                case 1:
                    break;
                case 2:
                    Console.WriteLine("==================================");
                    Console.WriteLine(player.FullDetailsToString());
                    Console.WriteLine("==================================");
                    this.displayGameMenu(player);
                    break;
                case 3:
                    property.purchaseProperty(player);
                    this.displayGameMenu(player);
                    break;
                case 4:
                    upgrade.buyHouse(player);
                    this.displayGameMenu(player);
                    break;
                case 5:
                    upgrade.buyHotel(player);
                    this.displayGameMenu(player);
                    break;
                case 6:
                    game.tradeProperty(player);
                    this.displayGameMenu(player);
                    break;
                case 7:
                    property.mortgageProperty(player);
                    this.displayGameMenu(player);
                    break;
                case 8:
                    Console.WriteLine("That option is not avaliable, please try again.");
                    this.displayGameMenu(player);
                    break;
                case 9:
                    Environment.Exit(0);
                    break;
                default:
                    Console.WriteLine("That option is not avaliable, please try again.");
                    this.displayGameMenu(player);
                    break;
            }
        }
示例#10
0
 public void TestDecimalInputCorrectlyParsesWithValidDecimalInput()
 {
     PlayerInput input = new PlayerInput();
     //decimal testDec = "3";
     //Assert.AreEqual(3, testDec);
 }
示例#11
0
        public Player displayPlayerChooser(ArrayList players, Player playerToExclude, String sPrompt)
        {
            PlayerInput input = new PlayerInput();

            //if no players return null
            if (players.Count == 0)
                return null;
            Console.WriteLine(sPrompt);
            //Create a new arraylist to display
            ArrayList displayList = new ArrayList(players);

            //remove the player to exlude
            displayList.Remove(playerToExclude);

            //go through and display each
            for (int i = 0; i < displayList.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, displayList[i].ToString());
            }
            //display prompt
            Console.Write("({0}-{1})>", 1, displayList.Count);
            //get input
            int resp = input.inputInteger();

            //if outside of range
            if ((resp < 1) || (resp > displayList.Count))
            {
                Console.WriteLine("That option is not avaliable. Please try again.");
                this.displayPlayerChooser(players, playerToExclude, sPrompt);
                return null;
            }
            else
            {
                Player chosenPlayer = (Player)displayList[resp - 1];
                //find the player to return
                foreach (Player p in players)
                {
                    if (p.getName() == chosenPlayer.getName())
                        return p;
                }
                return null;
            }
        }
示例#12
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);
            }
        }
示例#13
0
        //Allows the user to specify how many players are playing which have to be either 2 - 8 players
        public void setUpPlayers()
        {
            PlayerInput input = new PlayerInput();

            //Add players to the board
            Console.WriteLine("\nHow many players are playing?");
            Console.Write("(2-8)>");
            int playerCount = input.inputInteger();

            //if it is out of range then display msg and redo this method
            if ((playerCount < 2) || (playerCount > 8))
            {
                Console.WriteLine("\nThat is an invalid amount. Please try again.");
                this.setUpPlayers();
            }

            //Ask for players names
            for (int i = 0; i < playerCount; i++)
            {
                Console.WriteLine("Please enter the name for Player {0}:", i + 1);
                Console.Write(">");
                string sPlayerName = Console.ReadLine();
                Player player = new Player(sPlayerName);
                //subscribe to events
                player.playerBankrupt += playerBankruptHandler;
                player.playerPassGo += playerPassGoHandler;
                //add player
                Board.access().addPlayer(player);
                Console.WriteLine("{0} has been added to the game.", Board.access().getPlayer(i).getName());
            }
            Console.WriteLine("Players have been setup");
        }
示例#14
0
        public override void makePlay(int iPlayerIndex)
        {
            //Creates variable for player
            Player player = Board.access().getPlayer(iPlayerIndex);
            //Created variable for Game Menus
            GameMenus menu = new GameMenus();
            //Created variable for PlayerInput
            PlayerInput input = new PlayerInput();
            //Change the colour for the player
            Console.ForegroundColor = this.colors[iPlayerIndex];

            //if inactive skip turn
            if (player.isNotActive())
            {
                Console.WriteLine("\n{0} is inactive.\n", player.getName());
                //check players to continue
                //check that there are still two players to continue
                int activePlayerCount = 0;
                foreach (Player p in Board.access().getPlayers())
                {
                    //if player is active
                    if (!p.isNotActive())
                        //increment activePlayerCount
                        activePlayerCount++;
                }

                //if less than two active players display winner
                if (activePlayerCount < 2)
                {
                    this.printWinner();
                }
                return;
            }
            //prompt player to make move
            Console.WriteLine("{0}Your turn. Press Enter to make move", input.playerPrompt(iPlayerIndex));
            Console.ReadLine();
            //move player
            player.move();

            if (player.getInJail() == false)
            {
                //Display making move
                Console.WriteLine("*****Move for {0}:*****", player.getName());
                //Display rolling
                Console.WriteLine("{0}{1}\n", input.playerPrompt(iPlayerIndex), player.diceRollingToString());

                player.setLocation(player.getLocation() + player.getIMoveDistance());

                Property propertyLandedOn = Board.access().getProperty(player.getLocation());
                //landon property and output to console
                Console.WriteLine(propertyLandedOn.landOn(ref player));

                player.checkLandOnChance(ref player);
                player.checkLandOnCommunity(ref player);

                // Checks if the player has either landed on the "Go to Jail" board tile, or has received a "Go to Jail" chance or community chest card
                // If yes, player's turn ends
                if (player.checkSentToJail()) { return; }

                //Display player details
                Console.WriteLine("\n{0}{1}", input.playerPrompt(iPlayerIndex), player.BriefDetailsToString());

                // Checks if the player has landed on the Jail board tile, but has not been sent to Jail
                if ((player.getLocation() == 10) && (player.getInJail() == false))
                {
                    Console.WriteLine("{0} is visiting jail", player.getName());
                    menu.displayGameMenu(player);
                }

                // If player has not landed on Jail board tile, display player choice menu
                else if (player.getLocation() != 10)
                {
                    menu.displayGameMenu(player);
                }

                // Only other possibility is player is in Jail, not visiting
                else
                {
                    menu.displayJailMenu(player);
                }
            }
            else if (player.getInJail())
            {
                menu.displayJailMenu(player);
            }
        }