import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
class NewMain {
// Make global variables (grid&blobSize) which are accessible
// from anywhere inside the class FloodIntro
public static int blobSize;
"++--+++++++++++\n" +
"++---++++++++++\n" +
"+----++++++++++\n" +
"++++-++++++++++\n" +
"+++++++++++++++\n" +
"+++++++++++++++\n" +
"+++++++++-----+\n" +
"+++++++-----+++\n" +
"+++++-----+++++\n" +
"++++++------+++\n" +
"+++++++-----+++\n" +
"+++++++++--++++\n" +
"++++++++++-++++\n" +
"+++++++++++++++"));
ArrayList<String> lines = new ArrayList<String>();
int i = 0;
while ((str = in.readLine()) != null) {
grid[i] = str;
// System.out.println(str);
i++;
}
// so far can print out every line listed above
for (int x = 0; x < grid.length; x++) {
// for every line in the grid
for (int y = 0; y < grid[x].length(); y++) {
newGrid[x][y] = grid[x].charAt(y);
}
}
// Print out the current grid
displayGrid();
// variable to determine the size of the blob
blobSize = 0;
// Pick one random element in the array that is not along the
// border and remove the blob at that location
// NOTE: if a blank is chosen, the blob size is 0
// and nothing is removed
int blobRow = 3;
int blobCol = 3;
System.
out.
println("The blob at " + blobRow
+ "," + blobCol
+ " will be removed."); floodFill(blobRow, blobCol);
System.
out.
println("The blob had " + blobSize
+ " items in it"); System.
out.
println("The new grid is:"); // Print out the new grid
displayGrid();
}
public static void floodFill(int row, int col) {
if (newGrid[row][col].equals('-')) {
newGrid[row][col] = ' ';
blobSize++;
floodFill(row - 1, col - 1);
floodFill(row - 1, col);
floodFill(row - 1, col + 1);
floodFill(row, col - 1);
floodFill(row, col + 1);
floodFill(row + 1, col - 1);
floodFill(row + 1, col);
floodFill(row + 1, col + 1);
}
}
public static void displayGrid() {
for (int row = 0; row <= 14; row++) {
for (int col = 0; col <= 14; col++) {
output += newGrid[row][col];
}
output += "\n";
}
}
}