What you want to do is Given some coordinates (in the illustration is the center) and a color (orange in the illustration) you want to fill in all the points of the original color (white in the illustration) that are adjacent.A typical algorithm to do this is in recursive form.
The method jugada only checks if the data point has a color different from the past as a parameter; if not, there is no need to do anything. If so, call pintarRecursivo who does all the work. public static void jugada (int tablero[][], int color,int tamano ,int colores){
int x= 1 ; int y = 1 ;
if (tablero [x][y] != color) {
int colorARellenar = tablero[x][y];
pintarRecursivo (tablero, color, colorARellenar, x , y);
}
}
pintarRecursivo check if it is in a colored point that matches the colorARellenarIf so, it changes the color and calls recursively for the 4 adjacent coordinates. Checking before we leave the array. public static void pintarRecursivo (int tablero [][] , int color, int colorARellenar, int x , int y){
if ( x<0 || y<0 || x>=tablero.length || y>=tablero[x].length )
return;
if ( tablero[x][y]!=colorARellenar )
return;
tablero[x][y] = color;
pintarRecursivo( tablero, color, colorARellenar, x+1, y);
pintarRecursivo( tablero, color, colorARellenar, x, y+1);
pintarRecursivo( tablero, color, colorARellenar, x-1, y);
pintarRecursivo( tablero, color, colorARellenar, x, y-1);
}