Results 1 to 2 of 2
  1. #1
    stealthiskarl is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Question How would you shuffle a number of set x-y values and have them not overlap?

    I am making a program that displays boxes. Each box has a set x value and a set y value. I need to shuffle all the x values of the boxes (there happen to only be 2) and all the y values (there are 5) and then make sure they don't overlap. It should look like this:
    [] []
    [] []
    [] []
    [] []
    [] []

    When you hit a button it will take those boxes and just reorganize them into different spots. Thats what I need. PLEASE help, I've been working on this for hours. Its quite anoying

    My current code shuffles them, but it also has boxes that overlap. How do I fix this? Here is my Shuffle() function

    Java Code:
    if(buttonPressed){
    int i = 0;
    
    while (i < 10) {
    int[] q = { 
    155, 85, 355, 85, 155, 215, 355, 215, 155, 345, 355, 345, 155, 475, 355, 475, 155, 605, 355, 605
    };
    int z = ((int)((Math.random()*20)/2)*2);
    while (q[z] == -999) {
    z = ((int)((Math.random()*20)/2))*2;
    }
    Brain.xPos[i] = q[z];
    Brain.yPos[i] = q[z+1];
    
    q[z] = -999;
    
    
    
    System.out.println(Brain.xPos[i] + " " + q[z+1]);  //For debugging purposes only
    i++;
    
    }
    }

  2. #2
    stealthiskarl is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: How would you shuffle a number of set x-y values and have them not overlap?

    Never mind. The problem was I initialized q[] inside of the outer while Loop. I just had to take it out.

Similar Threads

  1. How to find the number of unique values in an Array
    By djbeko06 in forum New To Java
    Replies: 7
    Last Post: 09-12-2011, 09:45 AM
  2. How To Overlap Image
    By josephmacahasa in forum Java 2D
    Replies: 1
    Last Post: 08-19-2011, 09:58 AM
  3. Replies: 4
    Last Post: 10-31-2010, 05:19 PM
  4. overlap radius... help me..
    By tepong in forum New To Java
    Replies: 1
    Last Post: 08-21-2010, 08:41 PM
  5. [SOLVED] Best way to overlap Images?
    By Krooger in forum AWT / Swing
    Replies: 3
    Last Post: 06-08-2009, 06:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •