扫雷java源代码,导入java.awt。 *;导入java.awt.Event。 *;导入javax.swing。 *;公共类帧扩展JFrame {JTextField Text; Jlabel NowBomb,Setbomb;嵌体爆炸; //当前矿山,当前广场int rightbomb,restbomb,reastblock; //发现,剩下的矿井,剩下的数字jbutton start = new jbutton(“开始”); jpanel menupamel =新jpanel(); bombpanel =新jpanel();炸弹[] []轰炸顿; jpanel c; borderlayout borderlayout1 = new borderlayout(); gridlayout gridlayout1 = new gridlayout();公共框架(){try {setDefaultCloseoperation(Exit_On_Close); JBInit();} catch(例外例外){例外。 printstacktrace();}}}}}}}}}私有void jbinit()抛出异常{c =(jpanel)getContentPane(); stentle); C.SetBackground(Color.White); menupamel.setbackground(颜色。灰色); C.SetLayout(BorderLayout1);规定(新维度(600,600));可批准(假); blocknum = 144; Bombnum = 10;文本=新jtextfield(“10”,3); NowBomb = New Jlabel(“当前矿山”+“:”+ Bombnum); SetBomb =新JLabel(“设置矿物号”); start.addactionListener(new frame1_start_actionadapter(此)); menupamel.add(setbomb); menupamel.add(文字); menupamel.add(开始); menupamel.add(现在); C.ADD(Menupamel,Java.awt.borderlayout.south); bombpanel.setLayout; gridlayout1.setColumns((int)math.sqrt(blossnum); gridlayout1.setrows((int)math.sqrt(块);轰炸顿=新炸弹[(int)math.sqrt(块)] [(int)math.sqrt (块)]; for(int i = 0; i < (int) Math.sqrt(BlockNum); i++) { for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) { bombButton[i][j] = new Bomb(i, j); //bombButton[i][j].setSize(10, 10); bombButton[i][j].setFont(new Font("", Font.PLAIN, 14));//设置字体大小 bombButton[i][j].setForeground(Color.white); bombButton[i][j].addMouseListener(new Bomb_mouseAdapter(this)); bombButton[i][j].addActionListener(new Bomb_actionAdapter(this)); bombPanel.add(bombButton[i][j]); } } c.add(bombPanel, java.awt.BorderLayout.CENTER); startBomb(); } /* 开始按钮 */ public void start_actionPerformed(ActionEvent e) { int num=Integer.parseInt(text.getText().trim()); if (num > = 5 && num < 50) { BombNum = num; startBomb(); } else if (num < 5) { JOptionPane.showMessageDialog(null, "您设置的地雷数太少了,请重设!", "错误", JOptionPane.ERROR_MESSAGE); num=10; BombNum = num; } else { JOptionPane.showMessageDialog(null, "您设置的地雷数太多了,请重设!", "错误", JOptionPane.ERROR_MESSAGE); num=10; BombNum = num; } } /* 开始,布雷 */ public void startBomb() { nowBomb.setText("当前雷数" + ":" + BombNum); for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) { for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) { bombButton[i][j].isBomb = false; bombButton[i][j].isClicked = false; bombButton[i][j].isRight = false; bombButton[i][j].BombFlag = 0; bombButton[i][j].BombRoundCount = 9; bombButton[i][j].setEnabled(true); bombButton[i][j].setText(""); bombButton[i][j].setFont(new Font("", Font.PLAIN, 14));//设置字体大小 bombButton[i][j].setForeground(Color.BLUE); rightBomb = 0; restBomb = BombNum; restBlock = BlockNum - BombNum; } } for (int i = 0; i < BombNum; ) { int x = (int) (Math.random() * (int) (Math.sqrt(BlockNum) - 1)); int y = (int) (Math.random() * (int) (Math.sqrt(BlockNum) - 1)); if (bombButton[x][y].isBomb != true) { bombButton[x][y].isBomb = true; i++; } } CountRoundBomb(); } /* 计算方块周围雷数 */ public void CountRoundBomb() { for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) { for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) { int count = 0; // 当需要检测的单元格本身无地雷的情况下,统计周围的地雷个数 if (bombButton[i][j].isBomb != true) { for (int x = i - 1; x < i + 2; x++) { for (int y = j - 1; y < j + 2; y++) { if ( (x > = 0)&&(y> = 0)&&(x < ( (int) Math.sqrt(BlockNum))) && (y < ( (int) Math.sqrt(BlockNum)))) { if (bombButton[x][y].isBomb == true) { count++; } } } } bombButton[i][j].BombRoundCount = count; } } } } /* 是否挖完了所有的雷 */ public void isWin() { restBlock = BlockNum - BombNum; for (int i = 0; i < (int) Math.sqrt(BlockNum); i++) { for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) { if (bombButton[i][j].isClicked == true) { restBlock--; } } } if (rightBomb == BombNum || restBlock == 0) { JOptionPane.showMessageDialog(this, "您挖完了所有的雷,您胜利了!", "胜利", JOptionPane.INFORMATION_MESSAGE); startBomb(); } } /** 当选中的位置为空,则翻开周围的地图* */ public void isNull(Bomb ClickedButton) { int i, j; i = ClickedButton.num_x; j = ClickedButton.num_y; for (int x = i - 1; x < i + 2; x++) { for (int y = j - 1; y < j + 2; y++) { if ( ( (x != i) || (y != j)) && (x > = 0)&&(y> = 0)&& (x < ( (int) Math.sqrt(BlockNum))) && (y < ( (int) Math.sqrt(BlockNum)))) { if (bombButton[x][y].isBomb == false && bombButton[x][y].isClicked == false && bombButton[x][y].isRight == false) { turn(bombButton[x][y]); } } } } } /* 翻开 */ public void turn(Bomb ClickedButton) { ClickedButton.setEnabled(false); ClickedButton.isClicked = true; if (ClickedButton.BombRoundCount > 0){clickedbutton.settext +“”);否则{isnULL(ClickedButton);} / *左按钮* /公共void ActionPerformed(ActionEvent e){if((炸弹)e.getsource())。 isclicked == false &&((bomm)e.getsource())。 Isright == false){if((炸弹)e.getsource())。 ISBOMB == FALSE){转((炸弹)e.getsource()))))))))); iswin();} else {for(int i = 0; i < (int) Math.sqrt(BlockNum); i++) { for (int j = 0; j < (int) Math.sqrt(BlockNum); j++) { if (bombButton[i][j].isBomb == true) { bombButton[i][j].setText("b"); } } } ( (Bomb) e.getSource()).setForeground(Color.RED); ( (Bomb) e.getSource()).setFont(new Font("", Font.BOLD, 20)); ( (Bomb) e.getSource()).setText("X"); JOptionPane.showMessageDialog(this, "你踩到地雷了,按确定重来", "踩到地雷", 2); startBomb(); } } } /* 右键点击 */ public void mouseClicked(MouseEvent e) { Bomb bombSource = (Bomb) e.getSource(); boolean right = SwingUtilities.isRightMouseButton(e); if ( (right == true) && (bombSource.isClicked == false)) { bombSource.BombFlag = (bombSource.BombFlag + 1) % 3; if (bombSource.BombFlag == 1) { if (restBomb > 0){bombsource.setforeground(color.red); bombsource.settext(“f”); bombsource.ism = true; restbomb - ;} else {bombsource.bombflag = 0;}}否则if(bombsource.bombflag == 2){restbomb ++; bombsource.settext(“q”); bombsource .sright = false; else {bombsource.settext(“”);}如果(bombsource.bombomb == true){if(bombsource.bombflag == 1){rightbomb ++;} else(bombsource.bombflag = = 2){rightBomb - ;;}} novebomb.settext(“当前矿山”+“:”+ restbomb); Iswin();}}}}}}}}}}}}}}}}}}}}}公共静态void main(字符串[] args){帧框架=新帧();帧。 SERVISIBLE(TRUE);}}类FRAME1_START_ACTIONADAPTET实施ActionListener {私有框架Adaptee; Frame1_start_actionAdapter(帧适配者){this.adaptee =适配者;}公共无效的actionPerformed(ActionEvent的发送){adaptee.start_actionPerformed(E);}} //// //////////////// ////////////////////////// block int bombroundcount; //围绕着贻贝布尔isbomb; //是射线布尔·否决的; //你点击了INT BOMBFLAG; //雷标b le le s ;; {{num_x = x; num_y = y; Bombflag = 0; bombroundcount = 9; isbomb = false; isclicked = false; IsRight = false;}}} Bamb_ActionAdapter实现ActionListener {私有框架Adaptee; Bomb_ActionAdapter(Frame Adaptee){this.adaptee = Adaptee;}公共void actionPerformed(ActionEvent e){Adaptee.ActionPerformed(e);}}}}} Bamb_Mouseadapter延伸MouseAdapter {私人框架Adaptee; Bomb_Mouseadapter(Frame Adapeee){This.Adaptee = Adaptee;}公共空白Mouseclicked(MouseEvent e){Adaptee.mouseclicked(e);}}
有没有扫雷的源程序,Windos Mineslice的正常版本是解释Bray和Mine-Minesweepping计划。当我有一个矿山程序时,现在有很多来源下载,我不知道他们的算法是如何,但我想念我。该算法应该是更清晰且简单的。让我们谈谈我的矿山资料。首先,我们随机地把雷声放在矿井里,没有雷声,它将显示一个数字,表明它周围有几个雷鸣,这个实施如何?我们可以将整个矿区视为二维阵列A [i,j],例如射线:11 12 13 14 15 16 18 21 23 23 23 22 25 26 23 32 32 33 34 32 32 37 38 41 41 42 43 44 45 46 47 48 51 52 53 54 55 56 57 58我想知道围绕a [34]的几个雷,只检测[23],a [24],a [25] a [33], A [35] A [43],A [44],A [45] W留下八个雷声放在雷声中,仔细观察他们的数学关系。摘要是:雷鸣数的[i,j]是一个[i-1,j-1],a [i-1,j],a [i-1,j + 1] a [i, J-1],[I,J + 1] A [I + 1,J-1],[I + 1,J],[I + 1,J + 1](如果边界被超出判断)确定这个等级。 MineSweeping进程将自动启动一个没有雷声的无排灰区域。如果a [3,4]是1矿井矿,[2,3]已被标记为矿,则[24],a [25],a [33],a [35],a [43], [44],将部署A [45],以及无法形容的矿区。这也是实施的关键。我们可以将数组的元素设置为类对象,因此Windos MineSweeper正常版本的类与Minger和Min CL相结合耳朵。
C语言扫雷源代码 不用鼠标 操作 急求!!!,#include
#include #include #include #define n 3struct ine_box {char类型; //' *'代表我的,n由mines包围(n = 0-8)char bmarked; //标有炭束缚; //打开} mine_array [n] [n]; int currentrow,currentcol; //记录当前光标INT OpenedBlank = 0的位置; //将打开的晶格号/ *记录到屏幕上的指定位置的坐标* / void gotoxy(int x,int y){console_screen_buffer_info csbiinfo;处理hconsoleout; hconsoleout = getstdandle(std_output_handle); GetConsoloLoleCebufferInfo(HConsoleout,&CSBIInfo); csbiinfo.dwcursorposition.x = x; csbiinfo.dwcursorposition.y = y; setConsoleCurreposition(hconsoleout,csbiinfo.dwcursorposition);} //显示convoid Printbox的网格的帐篷(struct mine_box mb){//晶格未打开,如果(mb.boped == 0 && mb.bmarked == 0)Printf(“□”); //格子花呢披肩是标记的,如果(mb.bmarked = = 1)printf(“√”); //格子花呢标记为两次(MB.Bmarked == 2)Printf(“?”); //格子是打开的,显示格子elseswitch(mb.type)的内容{//格子有矿井案例'*':printf(“⊕”);打破; //格子没有矿山,没有矿井案例0:printf(“”);打破;案例1:printf(“1”);打破;案例2:Printf(“2”);打破;案例3:Printf(“3”);打破;案例4:Printf(“4”);打破;案例5:Printf(“5”)突破;案例6:Printf(“6”);打破;案例7:Printf(“7”);打破;案例8:Printf(“8”);打破;}} //将光标移动到行CoID MoveTo(int行,int co){currentrow =行; currentrow =行;currencol =金额; CurrentRow * 2 + 1);} //刷新屏幕VID刷新刷新(int状态){int i,j; gotoxy(0,0); printf(“┏┏”); for(i = 1; i 0){currentrow - ; moveto(currentrow,currencol);}}}} void movedown){if(currentrow 0){currencol - ; moveto(currentrow,currencol);}} void movertight(){}(currencol < N; i++)printf("┳━");printf("┓\n");for(i = 0; i < N; i++) {printf("┃");for(j = 0; j < N; j++) {if(state == -1 && mine_array[i][j].bMarked == 1 && mine_array[i][j].type != '*') {printf("¤"); // 标记错了地雷continue; } if(state != 0) { // 游戏结束,将所有的盒子掀开显示其中内容 mine_array[i][j].bOpened = 1;mine_array[i][j].bMarked = 0;}printBox(mine_array[i][j]);printf("┃");}if(i < N-1) {printf("\n┣");for(j = 1; j < N; j++) {printf("━╋");}printf("━┫\n");}else {printf("\n┗");for(j = 1; j < N; j++) {printf("━┻");}printf("━┛\n");}}printf("按键指南:A左移,D右移,W上移,S下移,X翻开,C标记,Q退出\n");}void MoveUp(){if(CurrentRow > n * n){printf(“数字overrober \ n”)return -1; memset((void *)mine_array,0,n * n * sizeof(struct mine_box)); //随机设置NUM灯SRAND(NULL)); for(i = 0; i < N-1) {CurrentRow ++;MoveTo(CurrentRow, CurrentCol);;}}void MoveLeft(){if(CurrentCol > = 0 && j> = 0 && i
责任编辑(张红爽)
以上就是关于**扫雷源码,网页版红包扫雷源码**的全部内容,了解更多请关注蚂蚁资源网。