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
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?
if (order[input] == orderByMouse_i) {
counter++;
println("correct");
} else println("wrong");
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.
post your entire code
mine should work
Yours doesn’t make sense
must be
if (order[clicked] == orderByMouse_i) {
I had input, just another variable name.
Gotta go
cu
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
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
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;
}
here is my version
It says “you won” only via println()
command
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;
}
//