My rect() is not working

At the bottom, the rect is not working.

String display[][];
int dificulty;
int size;
int position;
int ammount;
int margin;
float randomcol1 [];
float randomcol2 [];
float randomcol3 [];
float displaycol1 [][];
float displaycol2 [][];
float displaycol3 [][];
int click1x;
int click1y;
int click2x;
int click2y;  
boolean startcheck;
boolean win;
void setup() {
  size(1000,1000);
  dificulty = 4;
  display = new String[dificulty][dificulty];
  size = 900/dificulty;
  position = 1000/ dificulty;
  margin = 100/(dificulty*2);
  ammount = dificulty*dificulty/2;
  click1x = -1;
  click1y = -1;
  click2x = -1;
  click2y = -1;
  randomcol1 = new float[ammount];
  randomcol2 = new float[ammount];
  randomcol3 = new float[ammount];
  displaycol1 = new float[dificulty][dificulty];
  displaycol2 = new float[dificulty][dificulty];
  displaycol3 = new float[dificulty][dificulty];
  randomcol();
}

void draw() {
  
  background(255);
    for (int i = 0; i < dificulty; i++){
     for (int ii = 0; ii < dificulty; ii++){
       if(display[i][ii] == "turn"){
         fill(displaycol1[i][ii], displaycol2[i][ii], displaycol3[i][ii]);
         rect(position*ii+margin,position*i+margin,size,size);
    
       }else {
         fill(255);
         rect(position*ii+margin,position*i+margin,size,size);
        
       }
        
    } 
  }
  
  
}



void mouseReleased() {
  int x;
  int y;

  x = mouseX;
  y = mouseY;
  
  startcheck = false;
  for (int i = 0; i < dificulty; i++){
     for (int ii = 0; ii < dificulty; ii++){
       if(x >= position*ii+margin && x <= position*ii+margin+size){
         if(y >= position*i+margin && y <= position*i+margin+size){
           display[i][ii] = "turn";
           if (click1x == -1){
           click1x = ii;
           click1y = i;
           println(click1x);
         }else{
           click2x = ii;
           click2y = i;
           println(click2x);
           startcheck = true;
          
         }
        
       }
     }
  }
  if(startcheck){
    check();
  }
}

}

void randomcol(){
  int random1;
  int random2;
  boolean repeat = true;
  for(int i = 0; i <ammount; i++){
     
  randomcol1[i] = random(1,255);
  randomcol2[i] = random(1,255);
  randomcol3[i] = random(1,255);
  
  for(int ii = 0; ii < 2; ii++){
    repeat = true;
    while(repeat == true){
      
  random1 = int(random(0,dificulty));
  random2 = int(random(0,dificulty));
  
   if(displaycol1[random1][random2] == 0){
     displaycol1[random1][random2] = randomcol1[i];
     displaycol2[random1][random2] = randomcol2[i];
     displaycol3[random1][random2] = randomcol3[i];
      
      repeat = false;
   }
   }
   }
   
  }
  
 
}
  
  void check(){
    if(displaycol1[click1y][click1x] == displaycol1[click2y][click2x]){
      click1x = -1;
      click1y = -1;
      click2x = -1;
      click2y = -1;
      startcheck = false;
    }else {
      
      



   **<!------  fill(displaycol1[click2y][click2x], displaycol2[click2y][click2x], displaycol3[click2y][click2x]);**
**      rect(position*click2x+margin,position*click2y+margin,size,size);    ------------!>**





      delay(2000);
      display[click1y][click1x] = "";
      display[click2y][click2x] = "";
      click1x = -1;
      click1y = -1;
      click2x = -1;
      click2y = -1;
     
      
      startcheck = false;
    }
     
  }
1 Like

don’t use delay

use a timer instead

see here



String display[][];
int dificulty;
int size;
int position;
int ammount;
int margin;
float randomcol1 [];
float randomcol2 [];
float randomcol3 [];
float displaycol1 [][];
float displaycol2 [][];
float displaycol3 [][];
int click1x;
int click1y;
int click2x;
int click2y;
boolean startcheck;
boolean win;

int timer1=0;
boolean timerwaiting=false; 

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

void setup() {
  size(1000, 1000);
  dificulty = 4;
  display = new String[dificulty][dificulty];
  size = 900/dificulty;
  position = 1000/ dificulty;
  margin = 100/(dificulty*2);
  ammount = dificulty*dificulty/2;
  click1x = -1;
  click1y = -1;
  click2x = -1;
  click2y = -1;
  randomcol1 = new float[ammount];
  randomcol2 = new float[ammount];
  randomcol3 = new float[ammount];
  displaycol1 = new float[dificulty][dificulty];
  displaycol2 = new float[dificulty][dificulty];
  displaycol3 = new float[dificulty][dificulty];
  randomcol();
}

void draw() {

  if (timerwaiting) {

    if (millis()-timer1>2000) {
      display[click1y][click1x] = "";
      display[click2y][click2x] = "";
      click1x = -1;
      click1y = -1;
      click2x = -1;
      click2y = -1;
      startcheck = false;
      timerwaiting=false;
    } else {
      return;//leave
    }
  }

  background(255);
  for (int i = 0; i < dificulty; i++) {
    for (int ii = 0; ii < dificulty; ii++) {
      if (display[i][ii] == "turn") {
        fill(displaycol1[i][ii], displaycol2[i][ii], displaycol3[i][ii]);
        rect(position*ii+margin, position*i+margin, size, size);
      } else {
        fill(255);
        rect(position*ii+margin, position*i+margin, size, size);
      }
    }
  }
}

void mousePressed() {

  if (timerwaiting) {
    return;
  }

  int x;
  int y;

  x = mouseX;
  y = mouseY;

  startcheck = false;
  for (int i = 0; i < dificulty; i++) {
    for (int ii = 0; ii < dificulty; ii++) {
      if (x >= position*ii+margin && x <= position*ii+margin+size) {
        if (y >= position*i+margin && y <= position*i+margin+size) {
          display[i][ii] = "turn";
          if (click1x == -1) {
            click1x = ii;
            click1y = i;
            println(click1x);
          } else {
            click2x = ii;
            click2y = i;
            println(click2x);
            startcheck = true;
          }
        }
      }
    }
    if (startcheck) {
      check();
    }
  }
}

void randomcol() {
  int random1;
  int random2;
  boolean repeat = true;
  for (int i = 0; i <ammount; i++) {

    randomcol1[i] = random(1, 255);
    randomcol2[i] = random(1, 255);
    randomcol3[i] = random(1, 255);

    for (int ii = 0; ii < 2; ii++) {
      repeat = true;
      while (repeat == true) {

        random1 = int(random(0, dificulty));
        random2 = int(random(0, dificulty));

        if (displaycol1[random1][random2] == 0) {
          displaycol1[random1][random2] = randomcol1[i];
          displaycol2[random1][random2] = randomcol2[i];
          displaycol3[random1][random2] = randomcol3[i];

          repeat = false;
        }
      }
    }
  }
}

void check() {
  if (displaycol1[click1y][click1x] == displaycol1[click2y][click2x]) {
    click1x = -1;
    click1y = -1;
    click2x = -1;
    click2y = -1;
    startcheck = false;
  } else {


    fill(displaycol1[click2y][click2x], displaycol2[click2y][click2x], displaycol3[click2y][click2x]);
    rect(position*click2x+margin, position*click2y+margin, 
      size, size); 

    // delay(2000);
    timer1=millis();
    timerwaiting=true;
  }
}
//
1 Like