Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Monopoly program help!

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Monopoly program help!

    Ok im having a bit trouble in my monopoly program. Its a basic non finish program ( alot of things are not added) but it still runs. So far my program allows player 1 to go around the board and it will show his location and dice roll. But when it ask the player to purchase the location he lands on, the program get funky.

    Java Code: (when ask if you are playing with player 2 just type 0.)
    import java.util.*;
    public class Monopoly {
     
     
    	public static void main(String[] args) 
    	{
    		Scanner reader = new Scanner (System.in);
    		ArrayList<String> ownership = new ArrayList<String>();
     
    		Locations Move = new Locations();
    		Locations space = new Locations();
    		Locations pricepad = new Locations();
    		Locations location = new Locations();
    		//Locations die1 = new Locations();
     
    		Location1 Move1 = new Location1();
    		Location1 space1 = new Location1();
    		//Location1 die2 = new Location1();
     
    		Location2 Move2 = new Location2();
    		Location2 space2 = new Location2();
    		//Location2 die3 = new Location2();
     
    		Menus menu = new Menus();
    		Menus prices = new Menus();
    		Menus afterroll = new Menus();
    		Menus rules = new Menus ();
     
    		int roll,roll1,roll2,roll3,roll4;                   //Player's dice roll
    		int human, human1, human2, human3 = 0;              //Players
    		int price = 0,price1 = 0,price2 = 0,price3;         //Player's money
    		//int dice1, dice2;                                 //Dices for player1
    		//int dice3,dice4;                                  //Dice for player2
    		//int dice5,dice6;                                  //Dice for player3
    		//String menu1;                                     //Beginning turn menu
    		int menuOption;                                     //Beginning turn options
    		boolean game = false;
     
    		/*give the dice name to the dice in each class
    		 *Helps see if the user had roll a double
    		dice1 = die1.getMove();
    		dice2 = die1.getMove();
    		dice3 = die2.getMove();
    		dice4 = die2.getMove();
    		dice5 = die3.getMove();
    		dice6 = die3.getMove();*/
     
    		System.out.println(rules.getRules());
    		//See how many players are playing
     
    		System.out.println("\nIs player 1 playing? : ");
    		human = reader.nextInt();
    		System.out.println("\nIs player 2 playing? : ");
    		human1 = reader.nextInt();
    		System.out.println("\nIs player 3 playing? : ");
    		human2 = reader.nextInt();
    		 if ( human2 == 1){
    		   System.out.println("\nIs player 4 playing? : ");
    		human3 = reader.nextInt();
    		}
     
    		 //ASK USERS FOR A BEGINNING PRICE
    		 System.out.println("How much money would you like to start off with? ");
    		 menuOption = 5;
    		 while ( menuOption != 4){
    			 System.out.print(prices.getPrices());
    			 menuOption = reader.nextInt();
    			 System.out.println("");
     
    			 if( menuOption == 1){
    				 price = 1500;
    				 price1 = 1500;
    				 price2 = 1500;
    				 price3 = 1500;
    				 break;
    			 }
    			 else if ( menuOption == 2){
    				 price = 2000;
    				 price1 = 2000;
    				 price2 = 2000;
    				 price3 = 2000;
    				 break;
    			 }
    			 else if (menuOption == 3){
    				 price = 2500;
    				 price1 = 2500;
    				 price2 = 2500;
    				 price2 = 2500;
    				 break;
    			 }
    		 }
     
     
    		while ( game != true){
    		//Begin turn for player one
    		if(human == 1){
     
    		System.out.println("\nIts player 1 turn");	
     
    	     //Set menu up
    	      menuOption = 5;
    	      while (menuOption != 4)
    	      {
    	    	  System.out.print(menu.getMenu());
    	    	  menuOption = reader.nextInt();
    	    	  System.out.println("");
     
    	    	  if ( menuOption == 1)
    	    	  {
    	    		  roll1 = Move.getMove();
    	    		  space.getSpace();  
    	    	      System.out.print("\nYour rolled a " + roll1 +  " and landed on " + space.getLocations()+ " and you have $" + price + " left.");
    	    	     //Give a menu option to see if the player want to buy the location!
    	    	      menuOption = 3;
    	    	      //Do a if statement so the user wont have a chance in "buying" chance and community chest.
    	    	      if( space.getSpace() != 2 ||space.getSpace() != 4 ||space.getSpace() != 7 || space.getSpace() != 10 ||
    	    	      space.getSpace() != 17 || space.getSpace() != 20 || space.getSpace() != 22 || space.getSpace() != 30 ||
    	    	      space.getSpace() != 33){
    	    	      while ( menuOption != 2){
    	    	    	  System.out.print(afterroll.getAfterroll());
    	    	    	  menuOption = reader.nextInt();
    	    	    	  System.out.println("");
     
    	    	    	  if ( menuOption == 1)
    	    	    	  {
    	    	    		  if(pricepad.getSpace() > price)
    	    	    			  System.out.println("You doesnt have enough money!");
    	    	    		  else{
    	    	 	    		  price -= pricepad.getSpace();
    	    	    			  ownership.add(space.getLocations());
    	    	    			  System.out.println("Congrats you bought " + space.getLocations() + ", and have $" + price + " left.");//}
    	    	    		  break;
    	    	    	  }}
    	    	    	  else if ( menuOption == 2){
    	    	    		  System.out.println("Your turn will end!");
    	    	    	  }
    	    	      }}
    	    	      else if ( space.getSpace() == 4){
    	    	    	  System.out.println("You landed on Income Tax and you will pay $200 to the bank. ");
    	    	    	  price -= 200;
    	    	    	  break;
    	    	      }
    	    	      else if (space.getSpace() == 38 ){
    	    	    	  System.out.println("You landed on Luxury Tax and you will pay $100 to the bank. ");
    	    	    	  price -= 100;
    	    	    	  break;
    	    	      }
    	    	      break;
    	    	  }
    	    	  else if (menuOption == 2){
    	    		  System.out.println("You currently have $" +price+ ".");
    	    	  }
    	    	  else if (menuOption == 3){
    	    		  System.out.println("You currently own " + ownership);
    	    	  }
    	    	  else if (menuOption == 4){
    	    		  System.out.println("Please switch to player 2");
    	    	  }
     
    	    	  else
    	    		  //invalid option
    	    		  System.out.println("Invalid Option!");
    	      }
    	      System.out.println("\nPlease switch to player 2!");}
     
    		//BEGIN PLAYER 2 TURN
    		if(human1 == 1){
    			System.out.println("\nIts player 2 turn");	
    			//Set menu up
    		      menuOption = 5;
    		      while (menuOption != 4)
    		      {
    		    	  System.out.print(menu.getMenu());
    		    	  menuOption = reader.nextInt();
    		    	  System.out.println("");
     
    		    	  if ( menuOption == 1)
    		    	  {
    		  			roll2 = Move1.getMove();
    				    space1.getSpace();
    					System.out.print("\nYour rolled a " + roll2 +  " and landed on " + space1.getLocations() + " and you have $" + price1 + " left.");
    		    	      break;
    		    	  }
    		    	  else if (menuOption == 2){
    		    		  System.out.println("You currently have $" +price1);
    		    	  }
    		    	  else if (menuOption == 3){
    		    		  System.out.println("Doesnt work as of now, sorry.");
    		    	  }
    		    	  else if (menuOption == 4){
    		    		  System.out.println("Please switch to player 3");
    		    	  }
     
    		    	  else
    		    		  //invalid option
    		    		  System.out.println("Invalid Option!");
    		      }
    		      System.out.println("\nPlease switch to player 3!");}
     
    		//BEGIN PLAYER 3 TURN!
    		if(human2 == 1){
    			System.out.println("\nIts player 3 turn" );	
    			//Set menu up
    		      menuOption = 5;
    		      while (menuOption != 4)
    		      {
    		    	  System.out.print(menu.getMenu());
    		    	  menuOption = reader.nextInt();
    		    	  System.out.println("");
     
    		    	  if ( menuOption == 1)
    		    	  {
    		  			roll3 = Move2.getMove();
    					space2.getSpace();
    					System.out.print("\nYour rolled a " + roll3 +  " and landed on " + space2.getLocations()+ " and you have $" + price2 + " left.");
    		    	      break;
    		    	  }
    		    	  else if (menuOption == 2){
    		    		  System.out.println("You currently have $" +price1);
    		    	  }
    		    	  else if (menuOption == 3){
    		    		  System.out.println("Doesnt work as of now, sorry.");
    		    	  }
    		    	  else if (menuOption == 4){
    		    		  System.out.println("Please switch to player 3");
    		    	  }
     
    		    	  else
    		    		  //invalid option
    		    		  System.out.println("Invalid Option!");
    		      }
    		      System.out.println("\nPlease switch to player 1!");}
    Class:Menu
    /* 
     * The point of this class is to less cluther the monopoly program.
     * This class will store all menus for the game as well in the future the rules of monopoly.
      **************************Written by Lamar Nelson **********************************
     */
    public class Menus 
    {
          private String menu,prices,afterroll,rules;
     
          public String getMenu()
          {
        	  menu = "\n1) Would you like roll?(ONLY ONE PER TURN!, If you select this option after you rolled the first time then your turn will end!)"
    	    	   + "\n2) Would you like to view the amount of money you have?"
    	     	   + "\n3) Would you like to view properties bought? (DONT WORK RIGHT NOW!)"
    	    	   + "\n4) End Turn"
    	    	   + "\nEnter your option: ";
     
        	  return menu;
          }
     
          public String getPrices()
          {
        	  prices = "\n1) $1,500"
        		     + "\n2) $2,000"
        		     + "\n3) $2,500"
        		     + "\nEnter your option: ";
     
        	  return prices;
          }
     
          public String getAfterroll(){
     
        	  afterroll = "\n1) Would you like to purchase this?"
        		        + "\n2) Exit"
        		        + "\nEnter your option: ";
        	  return afterroll;
          }
     
          public String getRules(){
        	  rules = "Welcome to My Monopoly game! The rules in the game are simple: " 
    	           + "\n1.If you would like to say yes, then push the number (1) "
    	           + "\n2.If you would like to say no then push any other number!, Also EVERY NUMBER WILL NOT NEED A DECIMAL! DO NOT ENTER A DECIMAL NUMBERS SUCH AS (40.32)"
    	           + "\n3.ALOT OF THE OPTIONS DOESNT WORK YET! DO NOT SELECT OPTION 3, FOR THE 2ND MENU AND OPTION 1 FOR THE 3RD MENU!";
        	  return rules;
          }
    }
    Locations
     /* 
      *1. Point of this class is to less clutter the monopoly java program
      *2. Its gains dice1 and dice 2 then add them together to form move
      *3. getSpace is to store move, and add each roll together, so the player can go around the board
      *  a. If the space becomes greater than 40 (Last box in monopoly (GO)) then the equation below will allow the player "space" to reset
      *  ... which would allow them to bypass GO and land on the correct square 
      *4. getLocation is to store each location in the game of monopoly
      *  a. Its goes by the number of "space", if space equal 13 then the location will match the number 13 in the game of monopoly.
      *  b. pricepad is needed to store how much each property is worth, which would allow the player to purchase the property
      *    ... which will be subtracted from their income
      *  c. plocation is needed to store each property name, so if the player buy the property then they will be able to view it
      *               *********************** Future Task *********************************************
      *               1. Make it so, that when player pass go, then it will add $200 to the income
      *               
      *               *********************** Errors Found and Need to be Fix *************************
      *               1. In the Monopoly class when player buy a property a bug occurs
      *               - If player roll a 8 and land on the respected property, instead of the player..
      *               - buying the property he/she landed on, the player buys the property that's..
      *               - double the property number. (if player lands on 3 and want to buy, the program
      *               - make the player buy the 6th property instead)
      *               2. Player rolls, then player get "n" and lands on the "n" space, but when ask to 
      *               -buy, it do ( n * 2 = a, then a * 2) then but it on that space.
      *               -Rolled a 9, lands on Con. then program but me on 36 "chance"
      *                 
                      *********************** Written by Lamar Nelson ********************************* 
      */
    public class Locations 
    {
    	private static String location,plocation;
    	private static int dice1,dice2,move,space,pricepad;
    	Dice die1 = new Dice ();
     
    	public int getMove(){
    	dice1 = die1.getRoll();               //Get 1st dice
    	dice2 = die1.getRoll();
    	move = dice1 + dice2;
     
    	return move;
     
    	}
         public int getSpace()
         {
        	 space += move;
        	 if (space > 40){
        		 space = ((space - move) - 40) * -1;
        		 System.out.println("\nYou went pass go, you are awarded $200 ");
        		 pricepad = 200;}
        	 return space;
         }
    		public String getLocations ()
          {
     
    			if (space == 0)
    				location = "Go";
    			if ( space == 1){
    				location = ("Mediterranean Ave.");
    				pricepad = 60;}
    			if ( space == 2){
    				location = ("Community Chest");}
    			if ( space == 3){
    				location = ("Baltic Ave.");
    				pricepad = 60;}
    			if (space == 4){
    				location = ("Income Tax");
    				pricepad = 200;}
    			if ( space == 5){
    				location = ("Reading Railroad");
    				pricepad = 200;}
    			if (space == 6){
    				location = ("Oriental Ave.");
    				pricepad = 100;}
    			if ( space == 7)
    				location = ("Chance");
    			if ( space == 8){
    				location = ("Vermont Ave.");
    				pricepad = 100;}
    			if (space == 9){
    				location = ("Connecticut Ave.");
    				pricepad = 120;}
    			if ( space == 10)
    				location = ("Jail - Just Visiting");
    			if (space == 11){
    				location = ("St. Charles Place");
    				pricepad = 140;}
    			if ( space == 12){
    				location = ("Electric Company");
    				pricepad = 150;}
    			if ( space == 13){
    				location = ("States Ave.");
    				pricepad = 140;}
    			if ( space == 14){
    				location = ("Virginia Ave.");
    				pricepad = 160;}
    			if ( space == 15){
    				location = ("Pennsylvania Railroad ");
    				pricepad = 200;}
    			if ( space == 16){
    				location = ("St. James Place");
    				pricepad = 180;}
    			if ( space == 17){
    				location = ("Community Chest");}
    			if ( space == 18){
    				location = ("Tennessee Ave.");
    				pricepad = 180;}
    			if ( space == 19){
    				location = ("New York Ave.");
    				pricepad = 200;}
    			if (space == 20)
    				location = ("Free Parking");
    			if ( space == 21){
    				location = ("Kentucky Ave.");
    				pricepad = 220;}
    			if ( space == 22)
    				location = ("Chance");
    			if (space == 23){
    				location = ("Indiana Ave.");
    				pricepad = 220;}
    			if ( space == 24){
    				location = ("Illinois Ave.");
    				pricepad = 240;}
    			if ( space == 25){
    				location = ("B. & O. Railroad");
    				pricepad = 200;}
    			if ( space == 26){
    				location = ("Atlantic Ave.");
    				pricepad = 260;}
    			if ( space == 27){
    				location = ("Ventnor Ave.");
    				pricepad = 260;}
    			if ( space == 28){
    				location = ("Water Works");
    				pricepad = 150;}
    			if (space == 29){
    				location = ("Marvin Gardens");
    				pricepad = 280;}
    			if ( space == 30)
    				location = ("In Jail - out next turn");
    			if ( space == 31){
    				location = ("Pacific Ave.");
    				pricepad = 300;}
    			if (space == 32){
    				location = ("North Carolina Ave.");
    				pricepad = 300;}
    			if ( space == 33)
    				location = ("Community Chest");
    			if ( space == 34){
    				location = ("Pennsylvania Ave.");
    				pricepad = 320;}
    			if ( space == 35){
    				location = ("Short Line Railroad");
    				pricepad = 200;}
    			if ( space == 36)
    				location = ("Chance");
    			if ( space == 37){
    				location = ("Park Place");
    				pricepad = 350;}
    			if ( space == 38){
    				location = ("Luxury Tax");
    				pricepad = 100;}
    			if ( space == 39){
    				location = ("Boardwalk");
    				pricepad = 400;}
    			if ( space == 40){
    				location = ("Go");
    				pricepad = 200;}
    		//if (space > 40)
    		//{
    			//space = 40 - space ;
    		//}
     
    		//if ( space == 41)
    			//location = ("You are in jail (2nd turn)");
    		//if ( space == 42)
    			//location = ("You are in jail (Last turn)");
    		return location;  
          }
    }

    If there is a simpler way to do this, then please tell thanks


  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Monopoly program help!

    Welcome to My Monopoly game! The rules in the game are simple:
    1.If you would like to say yes, then push the number (1)
    2.If you would like to say no then push any other number!, Also EVERY NUMBER WILL NOT NEED A DECIMAL! DO NOT ENTER A DECIMAL NUMBERS SUCH AS (40.32)
    3.ALOT OF THE OPTIONS DOESNT WORK YET! DO NOT SELECT OPTION 3, FOR THE 2ND MENU AND OPTION 1 FOR THE 3RD MENU!

    Is player 1 playing? :
    1

    Is player 2 playing? :
    0

    Is player 3 playing? :
    0
    How much money would you like to start off with?

    1) $1,500
    2) $2,000
    3) $2,500
    Enter your option: 2


    Its player 1 turn

    1) Would you like roll?(ONLY ONE PER TURN!, If you select this option after you rolled the first time then your turn will end!)
    2) Would you like to view the amount of money you have?
    3) Would you like to view properties bought? (DONT WORK RIGHT NOW!)
    4) End Turn
    Enter your option: 1


    Your rolled a 5 and landed on Reading Railroad and you have $2000 left.
    1) Would you like to purchase this?
    2) Exit
    Enter your option: 1

    Congrats you bought Free Parking, and have $1980 left.

    Please switch to player 2!

    Thats whats happen..

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Monopoly program help!

    See posting at:
    Monopoly program help! - Java Forums

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM