# Can someone help me with this game? (image order)

**URL:** <https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147>\
**Category:** Coding Questions\
**Created:** [February 28, 2021, 7:01pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147 "2021-02-28T19:01:32Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 10:22pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/24 "2021-03-03T22:22:36Z")

</div>

Also you can use please println to see whether the if clause code is correct and shows whether it detects if the clicked image was correct

---

<div class="post-metadata">

**Author:** ![cocopuffs](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@cocopuffs](https://discourse.processing.org/u/cocopuffs)\
**Post date:** [March 3, 2021, 10:26pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/25 "2021-03-03T22:26:36Z")

</div>

if (order[input] == orderByMouse\_i)  
counter++;

orderByMouse\_i++;

so this isn’t what I should use to create an order of clicks and have “YOU WIN!” pop up when player clicks 4 correct ordered images, or “YOU LOSE!” if they click out of order?

So then I should use if and else if to create the variables to use an order for the images for the player to click and then use Text to inpuit the words?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 10:33pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/26 "2021-03-03T22:33:42Z")

</div>

> [@cocopuffs](#):
>
> if (order[input] == orderByMouse\_i)  
> counter++;
> 
> orderByMouse\_i++;

```auto
if (order[input] == orderByMouse_i) {
counter++;
println("correct");
} else println("wrong");

orderByMouse_i++;

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 10:34pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/27 "2021-03-03T22:34:43Z")

</div>

> [@cocopuffs](#):
>
> if (order[input] == orderByMouse\_i)  
> counter++;
> 
> orderByMouse\_i++;

use this to determine if the user clicks the right image,

AND DO NOT CHANGE IT.

write YOU WIN when counter is 4 and orderByMouse\_i is 4 too.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 10:43pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/29 "2021-03-03T22:43:40Z")

</div>

post your entire code

mine should work

Yours doesn’t make sense

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 10:46pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/31 "2021-03-03T22:46:07Z")

</div>

> [@cocopuffs](#):
>
> if (order[0] == orderByMouse\_i) {

must be

if (order[clicked] == orderByMouse\_i) {

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 10:46pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/32 "2021-03-03T22:46:52Z")

</div>

I had input, just another variable name.

Gotta go

cu

---

<div class="post-metadata">

**Author:** ![cocopuffs](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@cocopuffs](https://discourse.processing.org/u/cocopuffs)\
**Post date:** [March 3, 2021, 10:51pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/33 "2021-03-03T22:51:10Z")

</div>

I see, I thought I had to put 0. The code is showing correct now when I click the images in the correct order. Would I use this same area to put the text “YOU WIN!” when I click all 4 correct images? and “YOU LOSE!” when I click the wrong image? or is this it’s own separate code that needs to be created

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 3, 2021, 11:07pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/34 "2021-03-03T23:07:49Z")

</div>

In that area when counter is 4 etc. set a global variable win to true

Initially set it to false before setup()

In draw evaluate it with if and say text You won in this case

---

<div class="post-metadata">

**Author:** ![cocopuffs](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@cocopuffs](https://discourse.processing.org/u/cocopuffs)\
**Post date:** [March 4, 2021, 5:03am UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/37 "2021-03-04T05:03:22Z")

</div>

It worked!

//Initially set it to false before setup()  
boolean win = false;

//In draw evaluate it with if and say text You won in this case  
if(win == true){  
textSize(50);  
text(“YOU WIN!”, 290,415);  
} else if (orderByMouse\_i == 4){  
textSize(50);  
text(“TRY AGAIN!”, 290, 415);  
}

//In that area when counter is 4 etc. set a global variable win to true  
if(counter == 4){  
win = true;  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 9, 2021, 2:11pm UTC](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147/38 "2021-03-09T14:11:27Z")

</div>

here is my version

It says “you won” only via `println()` command

```auto
import java.util.*; 

PImage[] images= new PImage[4] ; //Declare an array of the type of PImage
ArrayList<Integer> list = new ArrayList();  

int[] order = new int[4] ; 
int[] orderByMouse = new int[4] ;

int counter = 0; 

int orderByMouse_i=0; 

void setup() {
  size(800, 800);

  images[0] = loadImage("IMG_2637_01.png");
  images[1] = loadImage("IMG_2637_02.png");
  images[2] = loadImage("IMG_2637_03.png");
  images[3] = loadImage("IMG_2637_04.png");

  for (PImage img : images) { 
    img.resize(400, 400); //image
  }

  list.add(0); 
  list.add(1);
  list.add(2);
  list.add(3);   

  Collections.shuffle(list);

  int i2=0; 
  for (Integer i : list) {
    order[i2] = i;
    println(order[i2], order[i2]+1); 
    i2++;
  }

  println("---------------");
}//func 

void draw() {
  background(255);

  image( images[order[0]], 0, 0);
  image( images[order[1]], 400, 0);
  image( images[order[2]], 0, 400);
  image( images[order[3]], 400, 400);
}

// --------------------------------------------------------------------

void mousePressed() {
  int input = -1;

  if (inside(0, 0)) input = 0;
  else if (inside(400, 0)) input = 1;
  else if (inside(0, 400)) input = 2;
  else if (inside(400, 400)) input = 3;

  // orderByMouse[orderByMouse_i] = input;
  // println(orderByMouse[orderByMouse_i]) ;
  println(order[input] == orderByMouse_i);

  if (order[input] == orderByMouse_i) 
    counter++; 

  orderByMouse_i++;

  if (orderByMouse_i==4) { 
    println("\ndone "+counter);
    if (counter==4)
      println("You won "+counter);
  }
}

// --------------------------------------------------------------------

boolean inside(int x, int y) {
  return 
    mouseX>x && 
    mouseY>y &&
    mouseX < x+400 && 
    mouseY < y+400;
}
//

```

[Previous page](https://discourse.processing.org/t/can-someone-help-me-with-this-game-image-order/28147.md?page=1)
