Help with grid game

I’m involved in a team project in college. the objective is to make a game for kids and the foundation is there. but when the mouse hover code works i have the other 8 squares in my 3x3 grid set to white. i want it to be where one other square turns red to be a target square for my hover code to get to. please help and respond asap.
thanks very much.

PFont f;
int time1 = 500;

int time2 = 3500;

float x = 0;

Cell [] grid;

int unit = 350; // size of one tile

int wideCount ;
int highCount ;

String[] list = {"4-5", "6-7", "8-9", "10-11", "", "12-13", "14-15", "16-17", "18+"}; 

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

void setup() {  
  size(1200, 1080);
   f = createFont("Times New Roman",16,true); // STEP 2 Create Font
  noStroke();
  background(255);
  int count;
  wideCount = width / unit; 
  highCount = height / unit; 
  count = wideCount * highCount;



  grid = new Cell[count];

  int index = 0;
  int k=0; 
  for (int x=0; x< wideCount; x++) {
    for (int y=0; y< highCount; y++) {
      //start creating objects
      grid[index] = new Cell (x*unit, y*unit, unit, list[k]);
      index++;
      k++;
    }
  }
}
//
void draw() {
  //
  background(255);
  int index = 0;
  //
  for (int x=0; x< wideCount; x++) {
    for (int y=0; y< highCount; y++) {
      grid[index++].display();
     
    }
     textFont(f,16); 
      fill(0);
      textAlign(CENTER);
  text("Stand on your AGE group to Play!",width/2,35); 

  }
}

// ========================================================================
// and the class


class Cell {
  float x, y;
  float side;
  String text=""; 
  
 
  //  int col;

  Cell (float tempX, float tempY, 
    float tempSide, 
    String tempText) {
    x = tempX;
    y = tempY;
    side = tempSide;
    text = tempText;
    //
    float fate = random(2);
  }

  void display() {
    int currentTime = millis();
    
    fill(255, 255, 255);
    stroke(122);
    fill(255, 255, 255);
    rect (x+width/9, y+height/9, side/2, side/2);
    fill(0,0,0);
    text(text, x+width/7.5+25, y+height/9+40); 
    if (mouseX>x&&mouseX<x+side&&mouseY>y&&mouseY<y+side) {
      fill(255, 0, 0);
      stroke(122);
      rect (x+width/9, y+height/9, side/2, side/2);
      fill(0,0,0);
      text(text, x+width/7.5+25, y+height/9+40);
      fill(0, 255, 0);
    } 
    
    if (currentTime > time2 & mouseX>x&&mouseX<x+side&&mouseY>y&&mouseY<y+side) {
      
      fill(0, 255, 0);
      stroke(122);
      rect (x+width/9, y+height/9, side/2, side/2);
      fill(0,0,0);
      text(text, x+width/7.5+25, y+height/9+40);
    }
  }
}
1 Like

That’s not easy to understand.

Do you mean you click a cell and it turns red?




PFont f;
int time1 = 500;

int time2 = 3500;

float x = 0;

Cell [] grid;

int unit = 350; // size of one tile

int wideCount ;
int highCount ;

String[] list = {"4-5", "6-7", "8-9", "10-11", "", "12-13", "14-15", "16-17", "18+"};

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

void setup() {
  size(1200, 1080);
  f = createFont("Times New Roman", 16, true); // STEP 2 Create Font
  noStroke();
  background(255);
  int count;
  wideCount = width / unit;
  highCount = height / unit;
  count = wideCount * highCount;

  grid = new Cell[count];

  int index = 0;
  int k=0;
  for (int x=0; x< wideCount; x++) {
    for (int y=0; y< highCount; y++) {
      //start creating objects
      grid[index] = new Cell (x*unit, y*unit, 
        unit, list[k]);
      index++;
      k++;
    }
  }
}
//
void draw() {
  //
  background(255);

  textFont(f, 16); 
  fill(0);
  textAlign(CENTER);

  int index = 0;
  //
  for (int x=0; x< wideCount; x++) {
    for (int y=0; y< highCount; y++) {
      grid[index++].display();
    }
  }//for
  text("Stand on your AGE group to Play!", width/2, 35);
}

void mousePressed() {
  int index = 0;

  for (int x=0; x< wideCount; x++) {
    for (int y=0; y< highCount; y++) {
      if (  grid[index].over()) {
        grid[index].selected=true;
      }
      index++;
    }
  }
}

// ========================================================================
// and the class

class Cell {

  float x, y;
  float side;
  String text="";

  // int col;

  boolean selected=false; 

  Cell (float tempX, float tempY, 
    float tempSide, 
    String tempText) {
    x = tempX;
    y = tempY;
    side = tempSide;
    text = tempText;
    //
    float fate = random(2);
  }

  void display() {
    int currentTime = millis();

    //  fill(255, 255, 255);
    stroke(122);
    fill(255, 255, 255);
    if (selected)
      fill(0, 0, 255);
    rect (x+width/9, y+height/9, side/2, side/2);
    // rect (x, y, side/2, side/2);
    fill(0, 0, 0);
    text(text, 
      x+width/7.5+25, y+height/9+40);

    // changed!!!!!!!!!!!!
    if (mouseX>x+width/9&&
      mouseX<x+width/9+side/2&&
      mouseY>y+height/9&&
      mouseY<y+height/9+side/2) {
      fill(255, 0, 0);
      stroke(122);
      if (selected)
        fill(0, 0, 255);
      rect (x+width/9, y+height/9, side/2, side/2);
      fill(0, 0, 0);
      text(text, x+width/7.5+25, y+height/9+40);
      fill(0, 255, 0);
    } 

    // changed!!!!!!!!!!!!
    //if (currentTime > time2 & mouseX>x&&mouseX<x+side&&mouseY>y&&mouseY<y+side) {
    //  fill(0, 255, 0);
    //  stroke(122);
    //  // rect (x+width/9, y+height/9, side/2, side/2);
    //  fill(0, 0, 0);
    //  //    text(text, x+width/7.5+25, y+height/9+40);
    //}
  }

  boolean over() {
    if (mouseX>x&&
      mouseX<x+side&&
      mouseY>y&&
      mouseY<y+side) {
      return true;
    }

    return false;
  }//method
  //
}//class
//