可按Ctrl+D收藏 蚂蚁资源网

蚂蚁资源网

欢乐扫雷源码(谁有扫雷群)

  • 时间:2021-02-12 15:13 编辑:金韶情 来源:蚂蚁资源 阅读:186
  • 扫一扫,手机访问
摘要:大家好,今天给大家介绍关于欢乐扫雷源码(谁有扫雷群)的相关内容,详细讲解java 扫雷源代码,扫雷java源代码,悬赏100元钱。注释一个java扫雷游戏源代码,就是把每行的意思写到后面就可以了!在线等。等,希望可以帮助到您。
java 扫雷源代码,导入java.awt.borderlayout;导入java.awt.Container;导入java.awt.font;导入java.awt.gridlayout;导入java.awt.insets;导入java.awt.Event.ActionEvent;导入java.awt.Event .actionListener;导入java.awt.event.mouseadapter;导入java.awt.Event.mouseEvent;导入javax.swing.jbutton;导入javax.swing.jframe;导入javax.swing.jlabel;导入javax.swing.jmenu;导入javax.swing.jmenubar;导入javax.swing.jmenuitem;导入javax.swing.jpanel;导入javax.swing.timer;公共类Scanlei1扩展JFrame实现ActionListener {私有静态最终长SerialVersionUID = 1L;私人集装箱康登琴;私人JButton BTN Private Jbutton [] Btns;私人Jlabel B1;私人Jlabel B2;私人Jlabel B3;私人计时器;私人int行= 9;私人int col =9;私人int bon = 10;私人int [] [] a;私人int b;私人int [] a1;私人JPanel P,P1,P2,P3;公共ScanLei1(字符串名称){62616964757a686964616fe58685e5aeb931333330323261super(标题); ContentPane = GetContentPane();规定(297,377);这个诱令(400,100,400,500); setDefaultCloseoperation(JFRAME.EXIT_ON_CLOSE);计时器=新计时器(1000,(ActionListener)这个); a = new int [行+ 2] [col + 2]; initgui} public void initgui(){p3 = new jpanel(); b = bon; jnder menubar = new jmenubar(); jmenu menu1 = new jmenu(“游戏”); JMENU MENU2 = NEW JMENU(“帮助”;“JMENIULEM MI1 = NEW JMENIULEM(”初级“); JMENIULEM MI2 = NEW JMENIULEM(”中间“); JMENIULEM MI3 = NEW JMENIULEM(”高级“); MI1.ADDACTIONLISTENER(此) ; menu1.add(mi1); mi2.addactionlistener(这个); menu1.add(mi2); mi3.addactionlistener(此); menu1.add(mi3); menubar.add(Menu1); menubar.add(Menu2); p3.add(菜单管); B1 = New Jlabel(Bon +“); A1 =新int [bon]; btn =新jbutton(“开始”); Btn.addactionListener(此); b2 =新jlabel(“0”); b3 = new jlabel(“”)btns = new jbutton [行* col]; p = new jpanel(); P.SetLayout(新的BanderLayout()); contentpane.add(p); p.add(p3,borderlayout.north); //组合= new jcombobox(new object [] {primary“,”中间“,”高级“}); //惊喜/*combo.additemlistener(新itemlistener(){}}); * / p1 =新jpanel(); //在该位置//(flowlayout)p1.getlayout())。 setAlignment(flowlayout.right); P1.ADD(B1); P1.ADD(B2); P1.ADD(B3); p.add(p3,borderlayout.north); p.add(p1,borderlayout.ceter); p2 =新jpanel();p2.setLayout(新的gridlayout(行,col,0,0)); for(int i = 0; i -1 && n -1 && m 行;如果(((n + col * q)> =(m * col))&&((n + col * q)<(m+1)*col)){ if(a[x-1][l]!=0&&a[x-1][l]!=10){ btns[n+col*q].setText(a[x-1][l]+""); a[x-1][l]=10; btns[n+col*q].setEnabled(false); } else if(a[x-1][l]==0){ //a[x-1][l]=10; btns[n+col*q].setEnabled(false); out(a,btns,e,n+col*q,x-1,l); ////55//// a[x-1][l]=10; btns[n+col*q].setEnabled(false); } p=0; } } } p=1; m=x; if(n> -1 && n -1 && m =(m * col))&&((n + col * q)<(m+1)*col)){ if(a[x+1][l]!=0&&a[x+1][l]!=10){ btns[n+col*q].setText(a[x+1][l]+""); a[x+1][l]=10; btns[n+col*q].setEnabled(false); } else if(a[x+1][l]==0){ out(a,btns,e,n+col*q,x+1,l);///55//// a[x+1][l]=10; btns[n+col*q].setEnabled(false); } p=0; } } } } int m=x-1; int n=y-1-1; p=1; if(n> -1 && n -1 && m =(m * col))&&(n + col * q)<(m+1)*col)){ if(a[x][y-1]!=0&&a[x][y-1]!=10){ btns[n+col*q].setText(a[x][y-1]+""); a[x][y-1]=10; btns[n+col*q].setEnabled(false); } else if(a[x][y-1]==0){out(a,btns,e,n+col*q,x,y-1); a[x][y-1]=10; btns[n+col*q].setEnabled(false); } p=0; } }} p=1; m=x-1; n=y+1-1; if(n> -1 && n -1 && m =(m * co))&&((n + col * q)<(m+1)*col)){ if(a[x][y+1]!=0&&a[x][y+1]!=10){ btns[n+col*q].setText(a[x][y+1]+""); a[x][y+1]=10; btns[n+col*q].setEnabled(false); } else if(a[x][y+1]==0){ out(a,btns,e,n+col*q,x,y+1); a[x][y+1]=10; btns[n+col*q].setEnabled(false); } p=0; } } }}}public void actionPerformed(ActionEvent e) {if(e.getActionCommand()=="初级"){row=9;col=9;bon=10;a1=new int[bon];b=bon;//setSize(297,377);a = new int[row+2][col+2];this.remove(p2);timer.stop();b1.setText("10");b2.setText("0");b3.setText("");btns=new JButton[row*col]; p2=new JPanel();p2.setLayout(new GridLayout(row,col,0,0));for(int i=0;i = 600){timer.stop();} else {t ++; b2.settext(t +“); for(int i = 0 i bon){b1.settext( bon +“);} else {b1.settext(b +”);} btns [i]。批评(true);}}}}}}}
扫雷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);}}
悬赏100元钱。注释一个java扫雷游戏源代码,就是把每行的意思写到后面就可以了!在线等。,导入java.awt。 *;导入java.util.random;导入java.awt.Event。 *; Class Min扩展JPanel //类类:鼠标左键= 1;右键= 3; Midkey = 2私有int标志= 0,statu = 0; //定义属性0:没有打开1:打开2:标记为Ray 3:不确定//标志= 0不是雷声;标志= 1是雷私有int,但数量= 0; //:按下哪个鼠标按钮:私有int mx = 0,my = 0,mw = 10; //定义mines的坐标和宽度()//构造函数{statu = 0;}公共min(int f,int x,int y,int w)//构造函数{flag = f; mx = x; my = y mw = w; public int getflag(){return标志;} public int getstatu(){return; public int getmx(){return mx;} public int getmy(){return我的;}公开int getmw){return mw;} public int getcount(public void setflag(int f){flag = f;} public void setcount(int c){count = c;} public void setdata(int f,int x,int y,int w / /根据差异鼠标要更改鼠标公共INT发送(int键){//返回值,返回-1 int = 1; if(key == 3){switch(staru){case 1:break; case 2:statu = 3;休息;案例3:statu = 0;断裂;案例0:statu = 2; break; rtn = 1;}如果(key == 1 && statu == 0){switch(标志){case 0:statu = 1 ; RTN = 2;休息;案例1:statu = 1; rtn = -1; break;}} return rtn;}}}类drawpanel扩展了jpanel {private int i,j;私有int f = 0; //如果f = 1那么游戏结束,如果f = 2那么赢得私有int chx = 0,chy = 0; //特别录制坐标x,y值私有int msum = 6,ksum = 0; // msum:ray号码,ksum:number私人车道int bx = 10,by = 10,bw = 40; // bx,by:chesssize,bw:棋子的符号public min porock [] [] = {new min(),新min(),新min(),新min(),新min(),新分钟(),新in new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),new min(),new min(),new min()new min(),new min(),new min(),new min(),new min()新min(),新的min( ),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),新min(),新min(),新的min(),新的min( ),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min()new min() ,new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),新min(),新分钟(),新分钟(),新m在(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新增min()new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),新min(),新min(),新的min (),新分钟(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),new min(),新min(),新min(),新分钟(),new min(),new min(),new min(),new min()new min(),new min(),new min(),new min(),新min(),新的min(),新的min( ),new min(),new min()(),new min(),new min(),new min(),new min(),new min(),{new min(),new min() ,new min(),new(),new min()new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),new min(),new min(),new min(),new min(),{new min(),new min(),new min(new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),新min(),新分钟(),new min(),new min()},{new min(),new min(),new min(),new min(),new min(),new min(),新min(), new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),{new min(),new min new min(),新min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min() ,new min(),new min(),new min(),new min(),{new min(),new min(),new min(),new min(),新min(),新分钟(),新分钟(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),new min(),新min(),新min(),新分钟()},{new min new min(),new min(),new min(),新min(),新min(),新m在(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(), new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(), new min(),new min(),new min(),new min()} {new min(),new min(),new min(),new min(),new min(),新min() ,new min(),new min new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min()()()()} ,new min(),new min(),new min(),new min(),new min(),new min()new min(),new min(),new min(),新min(), new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(), new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min()new min(),new min(),new min(),new min(),new min()new min(),new min(),new min(),新min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),新min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(),new min(),新min()新分钟(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(), new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(), new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),new min(),新min(), new min()n(),new min(),new min(),new min(),new min(),新min(),new min(),new min(),new min()min(),new min(),new min(),new min()},}; //绘在斧头,雷地区的雷霆的状态公共空白凹陷(图形g,int x,in yy){int x,y,w; //坐标x,y;和宽度:w int s,c,flag; // 状态;雷数; int cx = bw / 2 - 4; int cy = bw / 2 + 4; x =板[ax] [ayy] .getmx(); y =板[ax] [ayy] .getmy(); w =板[ax] [ay] .getmw(); s =板[ax] [ayy] .getstatu(); C =板[AX] [AY] .getCount();标志=板[AX] [AY] .getFlag();切换(s){case 0:// no打开状态{g .setcolor(color.black); g.filleRect(x,y,w,w);休息;}案例1://打开状态{g.setcolor(color.blue); g.filleRect(x,y,w),w); if(c!= 0 &&标志== 0)//没有θ{g.setcolor(color.red); g.drawstring(string.valueof(c),x + cx,y + cy); if(标志== 1)//在这里有雷声{g.setcolor(color.red); g.filleRect(x,y,w,w); G.SetColor(Color.Blue); G.Drawstring(“迅雷”,X + CX,Y + CY);突破;}案例2://层压状态{G.SetColor(Color.Green); g.filleRect(x,y,w,w); G.SetColor(Color.Blue); G.Drawstring(“标志”,X + CX,Y + CY);休息;}案例3://不确定状态{g.setcolor(color.black); g.filleRect(x,y,w,w); G.SetColor(颜色)红色); g.drawstring(“?”,x + cx,y + cyak;}} //没有图形绘图功能:绘制坐标轴,ay和图形公共空白绘制的状态(int ax,int ay){图形g; g = this.get.getraphics();绘制(g,斧头,ay);} //打开没有雷声的地方,绘画所在的地方并触发公共int undnmin(int斧头,int ay){int i,j; if(ax <1||ay<1||ax> bx || ay> by)返回0; //点击鼠标的区域(电路板[AX] [AY] .getStatu()!= 0)返回0; //如果打开此区域,请返回Board [Ax] [Ay] .sendkey(1); //如果返回返回值等于-1,则游戏结束绘制(AX,AY); if(板[AX] [AY] .getFlag()== 1)//如果游戏结束,则显示所有雷鸣{for(i = 1; i <=bx;i++) { for(j = 1;j <= by;j++) { if(board[i][j].getFlag() == 1) { board[i][j].sendKey(1); draw(i,j); } } } return -1; } //如果游戏没有结束 if(board[ax][ay].getCount() > 0){ksum ++;返回1; //周围有一个雷声,没有打开周围的区域}如果(板[Ax] [Ay] .getCount()== 0 && Board [Ax] [Ay] .getFlag()== 0)//没有雷声周围,​​打开周围的区域,直到有射线区域{undnomin(Ax-1,Ay-1); Opennomin(AX,AY-1); OpenNomin斧头+ 1,AY-1; Opennomin(AX-1,AY); Opennomin(Ax + 1,Ay); Opennomin(AX-1,AY + 1); Opennomin(AX.,啊+ 1); Opennomin(AX + 1,Ay + 1);} ksum ++;返回1;} //计算x,y public int getcount(int ai,int aj){int sum = 0的mines数; if(板[ai] [aj] .getflag()== 1){返回和;}如果(ai> 1 && aj> 1 && ai 1 && aj 1 && ai 1 && ai
责任编辑(金韶情

以上就是关于**欢乐扫雷源码,谁有扫雷群**的全部内容,了解更多请关注蚂蚁资源网。
  • 全部评论(3)
  • nij
  • 求j2me扫雷简单源代码,j2me版扫雷源代码SosoImg运行环境 Win2000,WinXP,WinVista,Windows7软件大小 12.26KB软件授权 免费软件分类rar文件软件标签j2me更新时间 2008-07-10
  • 2021-02-12 15:13:43
  • 织梦源码
  • 普通版本WINDOS扫雷程序是将布雷和扫雷结合扫雷程序思想讲解 在我大二的时候就编写了一个扫雷程序,现在也有很多源程序下载,我不知道他们的算法是怎么样的,但我想我的算法应是最清晰和简单的。下面就来讲解我的扫雷程序思想。 首先我们在雷区上随机地放上雷,没有雷的地方被点击后就会显示一个数字表示它周围有几个雷,这是怎么实现的呢?我们可以把整个雷区看成一个二维数组a[i,j],如雷区: 11 12 13 14 15 16 17 18 21 22 23 24 25 26 27 28 31 32 33 34 35 36 37 38 41 42 43 44 45 46 47 48 51 52 53 54 55 56 57 58我要知道a[34]周围有几个雷,就只有去检测 a[23],a[24],a[25] a[33], a[35] a[43],a[44],a[45]这8个雷区是否放上了雷,仔细观察它们成在数学关系。抽象出来就是:a[i,j]的雷的个数就是由 a[i-1,j-1],a[i-1,j],a[i-1,j+1] a[ i ,j-1], a[ i ,j+1] a[i+1,j-1],a[i+1,j],a[i+1,j+1] (如果超出边界再加以判断)这样的8个雷区决定的。 扫雷程序还会自动展开已确定没有雷的雷区。如果a[3,4]周围雷数为1,a[2,3]已被标示为地雷,那么a[24],a[25],a[33],a[35],a[43],a[44],a[45]将被展开,一直波及到不可确定的雷区。这也是实现的关键。我们可以把数组的元素设定为一个类对象,它们所属的类 因此普通版本WINDOS扫雷程序是将布雷和扫雷结合的
  • 2021-02-12 15:13:43
  • erpang666
  • #include”e69da5e887aae799bee5baa631333262363032stdio.h”#include”conio.h”#include”stdlib.h”#include”dos.h”#include”time.h” int a[16+1][30+1];/*数组用来存放地雷和数字的 */多出一个是用来控制边界的 int flag1,flag2;/*长宽调整标志*/ int color_flag=1,lei_number=10,high=8,width=8,face_flag=1; struct time1/*调用时间函数*/ {unsigned char ti_min; unsigned char ti_hour; unsigned charti_hund; unsigned char ti_sec;}t; void rect() { /*本模块的功能是在C界面上画边框,以增加C的友好性和可观性*/ int i; textcolor(14); textbackground(color_flag); clrscr();/*设置字体和背景颜色*/ gotoxy(1,2);putchar(201);/*左上角*/ for(i=1;i<79;i++) {gotoxy(i+1,2);putchar(205);}/*直线*/ putchar(187);/*右上角*/ for(i=2;i<23;i++) {gotoxy(80,i+1);putchar(186);}/*直线*/ gotoxy(80,24);putchar(188);/*右下角*/ for(i=1;i<79;i++) {gotoxy(i+1,24);putchar(205);}/*竖线*/ gotoxy(1,24);putchar(200);/*右上角*/ for(i=2;i<23;i++) {gotoxy(1,i+1);putchar(186);}/*竖线*/ gotoxy(30,1);cprintf(“WELCOMETO SAOLEI!”); gotoxy(28,25);cprintf(“COPYRIGHT---LANGCY---2002”);} void rect_s() { int i;/*根据长宽调整标志画边框*/ gotoxy(flag2-1,flag1-1);putchar(218); gotoxy(flag2+width*2-1,flag1-1);putchar(191); gotoxy(flag2-1,flag1+high);putchar(192); gotoxy(flag2+width*2-1,flag1+high);putchar(217); for(i=flag2;i<flag2+width*2-1;i++) {gotoxy(i,flag1-1);putchar(196); gotoxy(i,flag1+high);putchar(196);} for(i=flag1;i<flag1+high;i++) {gotoxy(flag2-1,i);putchar(179); gotoxy(flag2+width*2-1,i);putchar(179);}} void color()/*颜色选择*/ { char ch; rect(); gotoxy(25,6);cprintf(”This is the color table!”); gotoxy(30,8);cprintf(”1-black”); gotoxy(30,9);cprintf(”2-blue”); gotoxy(30,10);cprintf(”3-green”); gotoxy(30,11);cprintf(”4-bluesky”);gotoxy(30,12);cprintf(”5-red”); gotoxy(30,13);cprintf(”6-pink”); gotoxy(30,14); cprintf(”7-yellow”); gotoxy(30,15);cprintf(”8-gray”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the color numble:”); while(1) {ch=getch(); switch(ch) {case’1’: color_flag=0;cprintf(”black!”);break; case’2’: color_flag=1;cprintf(”blue!”);break; case’3’: color_flag=2;cprintf(”green!”);break; case’4’: color_flag=3;cprintf(”bluesky!”);break; case’5’: color_flag=4;cprintf(”red!”);break; case’6’: color_flag=5;cprintf(”pink!”);break; case’7’: color_flag=6;cprintf(”yellow!”);break; case’8’: color_flag=7;cprintf(”gray!”);break; case 27: main();break; case 13: main();break; default :break;}}} void size()/*选择大小*/ { char ch; rect(); gotoxy(25,8);cprintf(”This is the lei_size table!”); gotoxy(30,10);cprintf(”1--high=8,width=8”); gotoxy(30,11);cprintf(”2--high=8,width=16”); gotoxy(30,12);cprintf(”3--high=16,width=16”); go-toxy(30,13);cprintf(”4--high=16,width=20”); gotoxy(30,14);cprintf(”5--high=16,width=25”); go-toxy(30,15);cprintf(”6--high=16,width=30”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the lei_numble:”); while(1) {ch=getch(); switch(ch) { case’1’: high=8;width=8;cprintf(”high=8,width=8”);break; case’2’: high=8;width=16;cprintf(”high=8,width=16”);break; case’3’: high=16;width=16;cprintf(”high=16,width=16”);break; case’4’: high=16;width=20;cprintf(”high=16,width=20”);break; case’5’: high=16;width=25;cprintf(”high=16,width=25”);break; case’6’: high=16;width=30;cprintf(”high=16,width=30”);break; case 27: main();break; case 13: main();break; default :break; }}} void lei_num()/*选择雷的数目*/ { char ch; rect(); gotoxy(25,8);cprintf(”This is the lei_number table!”); gotoxy(30,10);cprintf(”1-10”); gotoxy(30,11);cprintf(”2-20”); gotoxy(30,12);cprintf(”3-40”); gotoxy(30,13);cprintf(”4-50”); gotoxy(30,14);cprintf(”5-80”); gotoxy(30,15);cprintf(”6-100”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the lei_numble:”); while(1) {ch=getch(); switch(ch) { case’1’: lei_number=10;cprintf(”10”);break; case’2’: lei_number=20;cprintf(”20”);break; case’3’: lei_number=40;cprintf(”40”);break; case’4’: lei_number=50;cprintf(”50”);break; case’5’: lei_number=80;cprintf(”80”);break; case’6’: lei_number=100;cprintf(”100”);break; case 27: main();break; case 13: main();break; default :break; }}} void face()/*选择图标*/ { char ch; rect(); gotoxy(25,8);cprintf(”This is the face table!”); gotoxy(30,10);cprintf(”1--smail face”); gotoxy(30,11);cprintf(”2--heart”); gotoxy(30,12);cprintf(”3--rectangle”); gotoxy(30,13);cprintf(”4--flower”); gotoxy(30,14);cprintf(”5--peach”); gotoxy(30,15);cprintf(”6--music”); gotoxy(30,16);cprintf(”ESC-main menu”); gotoxy(25,18);cprintf(”Please choose the face:”); while(1) {ch=getch(); switch(ch) { case’1’:face_flag=1;printf(”smail face!”);break; case’2’: face_flag=3;printf(”heart!”);break; case’3’: face_flag=4;printf(”rectangle!”);break; case’4’: face_flag=5;printf(”flower!”);break; case’5’: face_flag=6;printf(”peach!”);break; case’6’: face_flag=14;printf(”music!”);break; case 27: main();break; case 13: main();break; default :break;}}} void fail()/*没有扫成功,重新再来*/ { int i,j,t3,t4; char ch; flag1=(23-high)/2+2; flag2=(80-2*width)/2; for(i=1,t3=flag1;i<high+1;i++,t3++) for(j=1,t4=flag2;j<width+1;j++,t4+=2){ gotoxy(t4,t3); if(a[i][j]==-1) putchar(15); elseprintf(”%d”,a[i][j]); } gotoxy(25,23);printf(”Do you want to continue? <y/n>”); ch=getch(); if(ch==’y’||ch==’Y’) saolei(); elsemain();} void succeed()/*扫雷成功,再来否*/ { char ch; gotoxy(30,22);cprintf(”Congradulation! Youwin!”); gotoxy(25,23);printf(”Do you want to continue? <y/n>”); ch=getch(); if(ch==’y’||ch==’Y’) saolei(); else main();} saolei()/*扫雷函数*/ { int i,j,countlei,left=lei_number,time_flag1,time_flag2; int t1=1,t2=1,lei_flag=0,t3,t4; char ch; rect(); flag1=(23-high)/2+2; flag2=(80-2*width)/2; for(i=0;i<high+1;i++) for(j=0;j<width+1;j++) a[i][j]=0;/*初始值*/ while(lei_flag<=lei_number) { t1=1+random(high);t2=1+random(width); if(a[t1][t2]! =-1) { a[t1][t2]=-1; lei_flag++;}}/*随机赋地雷*/ for(i=1;i<high+1;i++) for(j=1;j<width+1;j++) { if(a[i][j]! =-1) { countlei=0;/*由于上面已经考虑了边界,这里不需判断边界*/ if(a[i-1][j-1]==-1) countlei++; if(a[i-1][j]==-1) countlei++; if(a[i-1][j+1]==-1) countlei++;if(a[i][j-1]==-1) countlei++; if(a[i][j+1]==-1) countlei++; if(a[i+1][j-1]==-1) countlei++; if(a[i+1][j]==-1) countlei++; if(a[i+1][j+1]==-1) countlei++; a[i][j]=countlei; } }/*计算各个地区周围的地雷的数目*/ rect_s();/*画小边框*/ for(i=1,t3=flag1;i<high+1;i++,t3++) for(j=1,t4=flag2;j<width+1;j++,t4+=2) {gotoxy(t4,t3);putchar(face_flag);} gotoxy(4,3);cprintf(”Left:%3d”,left); gotoxy(70,3);cprintf(”Time:000”); gettime(&t);/*从系统中取出时间*/ time_flag1=(int)t.ti_min*60+(int)t.ti_sec; i=1;j=1; while(1)/*键盘操作*/ { /*72-up,75-left,77-right,80-down,27-esc,13-enter,32-space*/ gettime(&t); time_flag2=(int)t.ti_min*60+(int)t.ti_sec-time_flag1; gotoxy(68,3);cprintf(”Time:%3d”,time_flag2); gotoxy(flag2,flag1); ch=getch(); switch(ch) { case 72 : i--;flag1--; if(i<=0) {i++;flag1++;} /*判断越界*/ gotoxy(flag2,flag1); break; case 75 : j--;flag2-=2; if(j<=0) {j++;flag2+=2;} gotoxy(flag2,flag1); break; case 77 : j++;flag2+=2;if(j>width) {j--;flag2-=2;} gotoxy(flag2,flag1);break; case 80 : i++;flag1++; if(i>high) {i--;flag1--;} gotoxy(flag2,flag1); break; case 32 : if(a[i][j]==-1) { putchar(15);left--; if(left==0) succeed();go-toxy(4,3);cprintf(”Left:%3d”,left); gotoxy(flag2,flag1); } else fail(); break; case 13 : if(a[i][j]! =-1) { printf(”%d”,a[i][j]); gotoxy(flag2,flag1); } if(a[i][j]==-1) fail(); break; case 27 : main();break; default : break;}}} main()/*主函数*/ { char ch; rect(); gotoxy(25,7);printf(”This is the main menu!”); gotoxy(30,9);printf(”Enter-start!”); gotoxy(30,10);printf(”1--Choose the color!”); gotoxy(30,11);printf(”2--Choose the size!”); gotoxy(30,12);printf(”3--Choose the lei_number!”); gotoxy(30,13);printf(”4--Choose the face!”); gotoxy(30,14);printf(”ESC--exit!”); gotoxy(25,16);printf(”Please select what you want!”); while(1) {ch=getch(); switch(ch) {case’1’: color();break; case’2’: size();break; case’3’: lei_num();break; case’4’: face();break; case 27: rect(); gotoxy(30,13); printf(”Thank you ! Good Bye!”); getch(); exit(0);break; case 13: saolei();break; default :break;}}}
  • 2021-03-25 19:30:01
最新发布的资讯信息
【简历/资料|内地女明星】 殷茹基本资料( YR个人简历介绍)(2020-12-06 15:19)
【简历/资料|内地女明星】 曹菁基本资料( CJ个人简历介绍)(2020-12-06 15:18)
【简历/资料|内地女明星】 王安妮基本资料( WAN个人简历介绍)(2020-12-06 15:18)
【简历/资料|内地女明星】 白琼基本资料( BQ个人简历介绍)(2020-12-06 15:17)
【简历/资料|内地女明星】 王世霞基本资料( WSX个人简历介绍)(2020-12-06 15:17)
【简历/资料|内地女明星】 宋煜基本资料( SY个人简历介绍)(2020-12-06 15:16)
【简历/资料|内地女明星】 钱增基本资料( QZ个人简历介绍)(2020-12-06 15:16)
【简历/资料|内地女明星】 胡晓黎基本资料( HXL个人简历介绍)(2020-12-06 15:15)
【简历/资料|内地女明星】 李佳慧基本资料( LJH个人简历介绍)(2020-12-06 15:15)
【简历/资料|内地女明星】 张洛嘉基本资料( ZLJ个人简历介绍)(2020-12-06 15:14)
联系客服
网站客服 联系客服
手机版

扫一扫进手机版
返回顶部