Click here to Skip to main content
15,900,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my program asks the user for a level of difficulty and based on their choice it randomly creates "baffles" to place inside of an array. My program creates the correct amount of baffles depending on what the user chooses. However, it puts them into different trays and I need them all in the same array.


here is my output:


Please choose a level of difficulty
1. Beginner: four baffles
2. Intermediate: seven baffles
3. Advanced: ten baffles 
1
BAFFLE1:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][R]
BAFFLE2:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][R][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
BAFFLE3:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][R][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
BAFFLE4:
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][L][ ][ ][ ][ ]


What I have tried:

JavaScript
public class PlayBaffleGame {
	public static void main (String [] args) {
		/*ask the user which level of difficulty they would like 
		to play and then display the game chosen board*/
	
		initializeBoard(null);

		int difficulty;
		Scanner input= new Scanner(System.in);
		 
		 System.out.println("Please choose a level of difficulty");
		 System.out.println("1. Beginner: four baffles");
		 System.out.println("2. Intermediate: seven baffles");
		 System.out.println("3. Advanced: ten baffles ");
		 
		 difficulty= input.nextInt();
		 int BaffleCount=0;
		 
		 
		 switch(difficulty) {
		 case 1:
			 //while loop to crate four baffles
				while(BaffleCount<4) {
					System.out.println("BAFFLE"+ (BaffleCount+1)+":");


					getBaffles();
					BaffleCount++;
				}
			 break;
		 case 2:
			 //while loop to create seven baffles
				while(BaffleCount<7) {
					System.out.println("BAFFLE"+ (BaffleCount+1)+":");

					getBaffles();
					BaffleCount++;
				}
			
			 break;
		 case 3:
			 //while loop to create ten baffles
				while(BaffleCount<10) {
					System.out.println("BAFFLE"+ (BaffleCount+1)+":");

					getBaffles();
					BaffleCount++;
				}
			 break;
		 } //end switch for difficulty 
		 
		 
	
		 
		
			
			
		
	}//end main method 

	
	
	
	//create method that uses random generated numbers to assign baffles a space
	public static void getBaffles() {
		
	 		int row= (int) (Math.random()*9+1);
			int col=(int) (Math.random()*9+1);
			int direction=(int)(Math.random()*2+1);
	 	
		for (int i = 0; i < 10; i++){
		 	
					    for (int j = 0; j < 	10; j++){
					     	
					    	  if(i==row&&j==col) {
						        	if(direction==1)
						        		System.out.print("[R]");
						        	else if(direction==2)
						        			System.out.print("[L]");
					      
					    }
					        else
					             System.out.print("[ ]");
					    } 
					    System.out.println();
					 
		}
		}//end getBaffles
Posted
Updated 5-Dec-17 16:40pm
v3

1 solution

Not to mention other things, just look at your getBaffles() method: You have a for loop for 10 iterations, at each iteration, the values of row, col, and direction remain the same as they are initialized before the loop, which means the 10 baffles are drawn on the same spot, got it? You may move on...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900