0

I have two images, put them in a list and repeat the second image to get a list with four images, three equal and one different.

Before placing the images on the screen I call Collections.shuffle (myList). The User has to click on any of the images.

How do I know if the User clicked on different image?

Greg
  • 1
  • 1

1 Answers1

1

What about instead of shuffling an image you shuffle a class?

class MyImage {
    MyImage(Image img, Boolean val, int x, int y){
      image = img;
      unique = val;
      posX = x;
      posY = y;
   }
}

You define a class like that, and add its coordinates and the boolean which defines if it is different.

Now you have to send the pointer event to the collection:

    public boolean isUnique(){
       return unique;
    }

    public void Intersects(int x, int y){
      if (x > posX && x < (posX + image.Width()) 
          && y > posY && y < (posY + image.Height())) {
            if (isUnique()) {
               // Perform action for unique image
            }
      } 
    }

So if the boolean you get is true, it means this is your unique image.

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
riktothepast
  • 121
  • 2
  • To add an Image on the screen, I add in ImageLayer. And ImageLayer only accepts object of type Image. How do I put in a MyImage ImageLayer? – Greg Jun 18 '12 at 14:14
  • Instead of MyImage(Image img, Boolean val, int x, int y) use MyImage(ImageLayer img, Boolean val, int x, int y){ – riktothepast Jun 23 '12 at 04:59