📄 group1.java
字号:
import java.awt.*;import java.awt.event.*;/* * Representation of a group of (same-coloured) bubbles for Bubblet. */public class Group1{ private Grid grid; private int nrows, ncols; private boolean[][] seen; private int color; private int size; /* Constructor */ public Group1 (Grid grid, int row, int col) { this.grid = grid; nrows = grid.nrows(); ncols = grid.ncols(); seen = new boolean[nrows][ncols]; for (int r = 0; r < nrows; r++) // for (int c = 0; c < grid.length(row); c++) for (int c = 0; c < ncols; c++) seen[r][c] = false; color = grid.get(row, col); size = flood(row, col); // System.out.println(); } /* Visit all unseen connected entries of given colour */ private int flood (int row, int col) { int num = 0; // Visit (row, col) if (col < grid.length(row) && ! seen[row][col] && grid.get(row, col) == color) { num++; seen[row][col] = true; // System.out.print(" " + row + " " + col + ", "); // Recursively visit each neighbouring entry if (row-1 >= 0) num += flood(row-1, col); if (row+1 < nrows) num += flood(row+1, col); if (col-1 >= 0) num += flood(row, col-1); if (col+1 < grid.length(row)) num += flood(row, col+1); } return num; } /* Return the size of the group */ public int size () { return size; } /* Return the score for this group */ public int score () { // int size = size(); return size * (size-1); } /* Return whether the group contains (row, col) */ public boolean contains (int row, int col) { return (col < grid.length(row) && seen[row][col]); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -