资源简介

期末大作业扫雷游戏单机版源码,可直接运行,eclipse中使用jdk1.8的编写。

资源截图

代码片段和文件信息

package sweeper;
import java.util.*;

public class GameData {
    ArrayList data;
    HashSet mines;
    int rows;
    int cols;
    int mineNum;
    /**
     * 获取游戏面板的长宽和雷数
     * @param r 长
     * @param c 宽
     * @param m 雷数
     */
    public GameData(int r int c int m){
        rows = r;
        cols = c;
        mines = new HashSet();
        mineNum = m;
        generateCells();
    }
    
    //制作游戏面板
    public void generateCells(){
     //面板每个方格组成数组
        data = new ArrayList();
        for(int i=0; i            data.add(0);
        }
        while(mines.size()            Random num =new Random();
            mines.add(num.nextInt(rows*cols));
        }
        for(Integer i: mines){
            int x;
            int y;
            if((x = i%cols) <0)
                x=x+cols;
            y = (i-x)/cols;
            //蛇形循环遍历八把游戏面板塞满
            if(x == 0){
                if(y == 0){
                    data.set(i+1data.get(i+1)+1);
                    data.set(i+colsdata.get(i+cols)+1);
                    data.set(i+cols+1data.get(i+cols+1)+1);
                } else if(y == rows-1){
                    data.set(i-cols+1data.get(i-cols+1)+1);
                    data.set(i-colsdata.get(i-cols)+1);
                    data.set(i+1data.get(i+1)+1);
                } else {
                    data.set(i+1data.get(i+1)+1);
                    data.set(i+colsdata.get(i+cols)+1);
                    data.set(i+cols+1data.get(i+cols+1)+1);
                    data.set(i-cols+1data.get(i-cols+1)+1);
                    data.set(i-colsdata.get(i-cols)+1);
                }
            }else if(x == cols-1){
                if(y == 0){
                    data.set(i-1data.get(i-1)+1);
                    data.set(i+colsdata.get(i+cols)+1);
                    data.set(i+cols-1data.get(i+cols-1)+1);
                }else if(y == rows-1){
                    data.set(i-cols-1data.get(i-cols-1)+1);
                    data.set(i-colsdata.get(i-cols)+1);
                    data.set(i-1data.get(i-1)+1);
                }else{
                    data.set(i-1data.get(i-1)+1);
                    data.set(i+colsdata.get(i+cols)+1);
                    data.set(i+cols-1data.get(i+cols-1)+1);
                    data.set(i-cols-1data.get(i-cols-1)+1);
                    data.set(i-colsdata.get(i-cols)+1);
                }
            }else {
                if(y == 0){
                    data.set(i+colsdata.get(i+cols)+1);
                    data.set(i+1data.get(i+1)+1);
                    data.set(i+cols+1data.get(i+cols+1)+1);
                    data.set(i-1data.get(i-1)+1);
                    data.set(i+cols-1data.get(i+cols-1)+1);
                }else if( y == cols-1){
                    data.set(i-cols+1data.get(i-cols+1)+1);
                    data.set(i-colsdata.get(i-cols)+1);
                    data.set(i+1data.get(i+1)+1);
        

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-05-26 17:55  sweeper\
     文件         301  2019-05-26 17:50  sweeper\.classpath
     文件         383  2019-05-26 17:55  sweeper\.project
     目录           0  2019-05-26 17:55  sweeper\.settings\
     文件         598  2019-05-26 17:50  sweeper\.settings\org.eclipse.jdt.core.prefs
     目录           0  2019-05-26 17:55  sweeper\bin\
     目录           0  2019-05-30 10:04  sweeper\bin\sweeper\
     文件        4087  2019-05-30 10:22  sweeper\bin\sweeper\GameData.class
     文件        1296  2019-05-30 10:23  sweeper\bin\sweeper\GameDialog$ButtonListener.class
     文件        3058  2019-05-30 10:23  sweeper\bin\sweeper\GameDialog.class
     文件        2236  2019-05-30 10:55  sweeper\bin\sweeper\GameGui$CellMouseListener.class
     文件        1136  2019-05-30 10:55  sweeper\bin\sweeper\GameGui$FaceListener.class
     文件        1131  2019-05-30 10:55  sweeper\bin\sweeper\GameGui$frameFoucsListener.class
     文件        1699  2019-05-30 10:55  sweeper\bin\sweeper\GameGui$MenuListener.class
     文件        1572  2019-05-30 10:55  sweeper\bin\sweeper\GameGui$MineTimer.class
     文件        7464  2019-05-30 10:55  sweeper\bin\sweeper\GameGui.class
     文件        2030  2019-05-30 10:14  sweeper\bin\sweeper\ImageCell.class
     目录           0  2019-05-26 17:55  sweeper\resource\
     文件         200  2019-05-26 17:51  sweeper\resource\0.png
     文件         215  2019-05-26 17:51  sweeper\resource\1.png
     文件         215  2019-05-26 17:51  sweeper\resource\10.png
     文件         255  2019-05-26 17:51  sweeper\resource\11.png
     文件         236  2019-05-26 17:51  sweeper\resource\12.png
     文件         224  2019-05-26 17:51  sweeper\resource\13.png
     文件         231  2019-05-26 17:51  sweeper\resource\14.png
     文件         188  2019-05-26 17:51  sweeper\resource\15.png
     文件         227  2019-05-26 17:51  sweeper\resource\2.png
     文件         223  2019-05-26 17:51  sweeper\resource\3.png
     文件         212  2019-05-26 17:51  sweeper\resource\4.png
     文件         220  2019-05-26 17:51  sweeper\resource\5.png
     文件         223  2019-05-26 17:51  sweeper\resource\6.png
............此处省略11个文件信息

评论

共有 条评论