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

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

时间:2014-11-14 11:08来源:网络整理 作者:网络 点击:
分享到:
public void randomBuild() { int randoms, cols, rows; for (int twins = 1; twins = 15; twins++) { randoms = (int) (Math.random() * 25 + 1); for (int alike = 1; alike = 2; alike++) { cols = (int) (Math.r

        public void randomBuild() {
                int randoms, cols, rows;
                for (int twins = 1; twins <= 15; twins++) {
                        randoms = (int) (Math.random() * 25 + 1);
                        for (int alike = 1; alike <= 2; alike++) {
                                cols = (int) (Math.random() * 6 + 1);
                                rows = (int) (Math.random() * 5 + 1);
                                while (grid[cols][rows] != 0) {
                                        cols = (int) (Math.random() * 6 + 1);
                                        rows = (int) (Math.random() * 5 + 1);
                                }
                                this.grid[cols][rows] = randoms;
                        }
                }
        }

        public void fraction() {
                fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable
                                .getText()) + 100));
        }

        public void reload() {
                int save[] = new int[30];
                int n = 0, cols, rows;
                int grid[][] = new int[8][7];
                for (int i = 0; i <= 6; i++) {
                        for (int j = 0; j <= 5; j++) {
                                if (this.grid[i][j] != 0) {
                                        save[n] = this.grid[i][j];
                                        n++;
                                }
                        }
                }
                n = n - 1;
                this.grid = grid;
                while (n >= 0) {
                        cols = (int) (Math.random() * 6 + 1);
                        rows = (int) (Math.random() * 5 + 1);
                        while (grid[cols][rows] != 0) {
                                cols = (int) (Math.random() * 6 + 1);
                                rows = (int) (Math.random() * 5 + 1);
                        }
                        this.grid[cols][rows] = save[n];
                        n--;
                }
                mainFrame.setVisible(false);
                pressInformation = false; // 这里一定要将按钮点击信息归为初始
                init();
                for (int i = 0; i < 6; i++) {
                        for (int j = 0; j < 5; j++) {
                                if (grid[i + 1][j + 1] == 0)
                                        diamondsButton[i][j].setVisible(false);
                        }
                }
        }

精彩图集

赞助商链接