龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

java基于swing实现的连连看代码(4)

时间:2014-11-14 11:08来源:网络整理 作者:网络 点击:
分享到:
public void xiao() { // 相同的情况下能不能消去。仔细分析,不一条条注释 if ((x0 == x (y0 == y + 1 || y0 == y - 1)) || ((x0 == x + 1 || x0 == x - 1) (y0 == y))) { // 判断是否相

        public void xiao() { // 相同的情况下能不能消去。仔细分析,不一条条注释
                if ((x0 == x && (y0 == y + 1 || y0 == y - 1))
                                || ((x0 == x + 1 || x0 == x - 1) && (y0 == y))) { // 判断是否相邻
                        remove();
                } else {
                        for (j = 0; j < 7; j++) {
                                if (grid[x0][j] == 0) { // 判断第一个按钮同行哪个按钮为空
                                        if (y > j) { // 如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边
                                                for (i = y - 1; i >= j; i--) { // 判断第二按钮左侧直到第一按钮中间有没有按钮
                                                        if (grid[x][i] != 0) {
                                                                k = 0;
                                                                break;
                                                        } else {
                                                                k = 1;
                                                        } // K=1说明通过了第一次验证
                                                }
                                                if (k == 1) {
                                                        linePassOne();
                                                }
                                        }
                                        if (y < j) { // 如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边
                                                for (i = y + 1; i <= j; i++) { // 判断第二按钮左侧直到第一按钮中间有没有按钮
                                                        if (grid[x][i] != 0) {
                                                                k = 0;
                                                                break;
                                                        } else {
                                                                k = 1;
                                                        }
                                                }
                                                if (k == 1) {
                                                        linePassOne();
                                                }
                                        }
                                        if (y == j) {
                                                linePassOne();
                                        }
                                }
                                if (k == 2) {
                                        if (x0 == x) {
                                                remove();
                                        }
                                        if (x0 < x) {
                                                for (n = x0; n <= x - 1; n++) {
                                                        if (grid[n][j] != 0) {
                                                                k = 0;
                                                                break;
                                                        }
                                                        if (grid[n][j] == 0 && n == x - 1) {
                                                                remove();
                                                        }
                                                }
                                        }
                                        if (x0 > x) {
                                                for (n = x0; n >= x + 1; n--) {
                                                        if (grid[n][j] != 0) {
                                                                k = 0;
                                                                break;
                                                        }
                                                        if (grid[n][j] == 0 && n == x + 1) {
                                                                remove();
                                                        }
                                                }
                                        }
                                }
                        }
                        for (i = 0; i < 8; i++) { // 列
                                if (grid[i][y0] == 0) {
                                        if (x > i) {
                                                for (j = x - 1; j >= i; j--) {
                                                        if (grid[j][y] != 0) {
                                                                k = 0;
                                                                break;
                                                        } else {
                                                                k = 1;
                                                        }
                                                }
                                                if (k == 1) {
                                                        rowPassOne();
                                                }
                                        }
                                        if (x < i) {
                                                for (j = x + 1; j <= i; j++) {
                                                        if (grid[j][y] != 0) {
                                                                k = 0;
                                                                break;
                                                        } else {
                                                                k = 1;
                                                        }
                                                }
                                                if (k == 1) {
                                                        rowPassOne();
                                                }
                                        }
                                        if (x == i) {
                                                rowPassOne();
                                        }
                                }
                                if (k == 2) {
                                        if (y0 == y) {
                                                remove();
                                        }
                                        if (y0 < y) {
                                                for (n = y0; n <= y - 1; n++) {
                                                        if (grid[i][n] != 0) {
                                                                k = 0;
                                                                break;
                                                        }
                                                        if (grid[i][n] == 0 && n == y - 1) {
                                                                remove();
                                                        }
                                                }
                                        }
                                        if (y0 > y) {
                                                for (n = y0; n >= y + 1; n--) {
                                                        if (grid[i][n] != 0) {
                                                                k = 0;
                                                                break;
                                                        }
                                                        if (grid[i][n] == 0 && n == y + 1) {
                                                                remove();
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }

精彩图集

赞助商链接