Hello,
First I show you my code.
int[] randomZahl = {3,6,8,9,4};
void setup(){
size(500,500);
}
void draw(){
line(100,0,100,500);
line(200,0,200,500);
line(300,0,300,500);
line(400,0,400,500);
line(500,100,0,100);
line(500,200,0,200);
line(500,300,0,300);
line(500,400,0,400);
}
void mouseClicked(){
int a = 0;
//Zeile 1
if(mouseX<=100 && mouseY<=100){
rect(0,0,100,100);
a = 1;
}
else if(mouseX<=200 && mouseX>=100 && mouseY<=100 && mouseY>=0){
rect(100,0,100,100);
a = 2;
}
else if(mouseX<=300 && mouseX>=200 && mouseY<=100 && mouseY>=0){
rect(200,0,100,100);
a = 3;
}
else if(mouseX<=400 && mouseX>=300 && mouseY<=100 && mouseY>=0){
rect(300,0,100,100);
a = 4;
}
else if(mouseX<=500 && mouseX>=400 && mouseY<=100 && mouseY>=0){
rect(400,0,100,100);
a = 5;
}
//Zeile 2
else if(mouseX<=100 && mouseX>=0 && mouseY<=200 && mouseY>=100){
rect(0,100,100,100);
a = 6;
}
else if(mouseX<=200 && mouseX>=100 && mouseY<=200 && mouseY>=100){
rect(100,100,100,100);
a = 7;
}
else if(mouseX<=300 && mouseX>=200 && mouseY<=200 && mouseY>=100){
rect(200,100,100,100);
a = 8;
}
else if(mouseX<=400 && mouseX>=300 && mouseY<=200 && mouseY>=100){
rect(300,100,100,100);
a = 9;
}
else if(mouseX<=500 && mouseX>=400 && mouseY<=200 && mouseY>=100){
rect(400,100,100,100);
a = 10;
}
//Zeile 3
else if(mouseX<=100 && mouseX>=0 && mouseY<=300 && mouseY>=200){
rect(0,200,100,100);
a = 11;
}
else if(mouseX<=200 && mouseX>=100 && mouseY<=300 && mouseY>=200){
rect(100,200,100,100);
a = 12;
}
else if(mouseX<=300 && mouseX>=200 && mouseY<=300 && mouseY>=200){
rect(200,200,100,100);
a = 13;
}
else if(mouseX<=400 && mouseX>=300 && mouseY<=300 && mouseY>=200){
fill(0);
rect(300,200,100,100);
a = 14;
}
else if(mouseX<=500 && mouseX>=400 && mouseY<=300 && mouseY>=200){
rect(400,200,100,100);
a = 15;
}
//Zeile 4
else if(mouseX<=100 && mouseX>=0 && mouseY<=400 && mouseY>=300){
rect(0,300,100,100);
a = 16;
}
else if(mouseX<=200 && mouseX>=100 && mouseY<=400 && mouseY>=300){
rect(100,300,100,100);
a = 17;
}
else if(mouseX<=300 && mouseX>=200 && mouseY<=400 && mouseY>=300){
rect(200,300,100,100);
a = 18;
}
else if(mouseX<=400 && mouseX>=300 && mouseY<=400 && mouseY>=300){
rect(300,300,100,100);
a = 19;
}
else if(mouseX<=500 && mouseX>=400 && mouseY<=400 && mouseY>=300){
rect(400,300,100,100);
a = 20;
}
//Zeile 5
else if(mouseX<=100 && mouseX>=0 && mouseY<=500 && mouseY>=400){
rect(0,400,100,100);
a = 21;
}
else if(mouseX<=200 && mouseX>=100 && mouseY<=500 && mouseY>=400){
rect(100,400,100,100);
a = 22;
}
else if(mouseX<=300 && mouseX>=200 && mouseY<=500 && mouseY>=400){
rect(200,400,100,100);
a = 23;
}
else if(mouseX<=400 && mouseX>=300 && mouseY<=500 && mouseY>=400){
rect(300,400,100,100);
a = 24;
}
else if(mouseX<=500 && mouseX>=400 && mouseY<=500 && mouseY>=400){
rect(400,400,100,100);
a = 25;
}
for(int i = 0; i < randomZahl.length; ++i){
if(randomZahl[i] == a){
fill(0);
}
}
}
So for loop should check if a is in the array, the box should get filled with a colour.
But my solution didnt work? Why?