import java.awt.Button; import java.awt.FlowLayout; import java.awt.Font; import java.awt.Frame; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; public class SaoLei extends Frame implements ActionListener{ private static SaoLei sl; private Label title,weizhi1,weizhi2,tishi; //定义了25个地方 private Button start,exit,last,lei1,lei2,lei3,lei4,lei5,lei6,lei7,lei8,lei9,lei10,lei11,lei12,lei13,lei14,lei15,lei16,lei17,lei18,lei19,lei20,lei21,lei22,lei23,lei24,lei25; private int e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18,e19,e20,e21,e22,e23,e24,e25; private int a[]=new int[25]; private int b[][]=new int[5][5]; private int ss=0; private int shu=0; private Label time; private boolean bz=false; private int miao; static int leishu; static SaoLeiRunnable slr; static Thread t; public int getMiao() { return miao; } public void setMiao(int miao) { this.miao = miao; } public Label getTime(){ return time; } public boolean isBz() { return bz; } public void setBz(boolean bz) { this.bz = bz; } public SaoLei(){ } public SaoLei(String name){ super(name); setLayout(new FlowLayout());//布局方式(流布局) title=new Label(" 魏振松的扫雷游戏 "); Font f=new Font("字体",3,30); title.setFont(f); add(title); weizhi1=new Label(" "); add(weizhi1); start=new Button("开始游戏"); add(start); exit=new Button("退出游戏"); add(exit); last=new Button("上一步"); add(last); start.addActionListener(this); exit.addActionListener(this); last.addActionListener(this); weizhi2=new Label(" "); add(weizhi2); time=new Label(" 0秒 "); add(time); lei1=new Button(" ");lei2=new Button(" ");lei3=new Button(" ");lei4=new Button(" "); lei5=new Button(" ");lei6=new Button(" ");lei7=new Button(" ");lei8=new Button(" ");lei9=new Button(" "); lei10=new Button(" ");lei11=new Button(" ");lei12=new Button(" ");lei13=new Button(" ");lei14=new Button(" "); lei15=new Button(" ");lei16=new Button(" ");lei17=new Button(" ");lei18=new Button(" ");lei19=new Button(" "); lei20=new Button(" ");lei21=new Button(" ");lei22=new Button(" ");lei23=new Button(" ");lei24=new Button(" "); lei25=new Button(" "); add(lei1);add(lei2);add(lei3);add(lei4);add(lei5);add(lei6);add(lei7);add(lei8);add(lei9);add(lei10); add(lei11);add(lei12);add(lei13);add(lei14);add(lei15);add(lei16);add(lei17);add(lei18);add(lei19);add(lei20); add(lei21);add(lei22);add(lei23);add(lei24);add(lei25); lei1.addActionListener(this);lei2.addActionListener(this);lei3.addActionListener(this);lei4.addActionListener(this);lei5.addActionListener(this); lei6.addActionListener(this);lei7.addActionListener(this);lei8.addActionListener(this);lei9.addActionListener(this);lei10.addActionListener(this); lei11.addActionListener(this);lei12.addActionListener(this);lei13.addActionListener(this);lei14.addActionListener(this);lei15.addActionListener(this); lei16.addActionListener(this);lei17.addActionListener(this);lei18.addActionListener(this);lei19.addActionListener(this);lei20.addActionListener(this); lei21.addActionListener(this);lei22.addActionListener(this);lei23.addActionListener(this);lei24.addActionListener(this);lei25.addActionListener(this); tishi=new Label(" "); Font f2=new Font("字体",3,20); tishi.setFont(f2); add(tishi); setSize(400,400);//设置窗口大小 setVisible(true);//设置是否可见 setResizable(false);//设置是否可调整大小 } public void setView(){ setVisible(true);//设置是否可见 } public static SaoLei getS(){ if(sl!=null){ return sl; }else{ sl=new SaoLei("魏振松的扫雷游戏"); return sl; } } public void chushihua(){ lei1.setLabel(" ");lei2.setLabel(" ");lei3.setLabel(" ");lei4.setLabel(" "); lei5.setLabel(" ");lei6.setLabel(" ");lei7.setLabel(" ");lei8.setLabel(" "); lei9.setLabel(" ");lei10.setLabel(" ");lei11.setLabel(" ");lei12.setLabel(" "); lei13.setLabel(" ");lei14.setLabel(" ");lei15.setLabel(" ");lei16.setLabel(" "); lei17.setLabel(" ");lei18.setLabel(" ");lei19.setLabel(" ");lei20.setLabel(" "); lei21.setLabel(" ");lei22.setLabel(" ");lei23.setLabel(" ");lei24.setLabel(" "); lei25.setLabel(" "); e1=0;e2=0;e3=0;e4=0;e5=0;e6=0;e7=0;e8=0;e9=0;e10=0;e11=0;e12=0;e13=0;e14=0;e15=0;e16=0;e17=0;e18=0;e19=0;e20=0;e21=0;e25=0;e22=0;e23=0;e24=0; ss=0; shu=0; start.setLabel("开始游戏"); tishi.setText(" "); time.setText(" 0秒 "); miao=-1; bz=false; } public void actionPerformed(ActionEvent event) { // TODO Auto-generated method stub if(event.getSource()==last){ setVisible(false);//设置是否可见 e1=0;e2=0;e3=0;e4=0;e5=0;e6=0;e7=0;e8=0;e9=0;e10=0;e11=0;e12=0;e13=0;e14=0;e15=0;e16=0;e17=0;e18=0;e19=0;e20=0;e21=0;e25=0;e22=0;e23=0;e24=0; ss=0; shu=0; start.setLabel("开始游戏"); tishi.setText(" "); time.setText(" 0秒 "); miao=-1; bz=false; Start.main(null); } if(event.getSource()==start){ a=new int[25]; b=new int[5][5]; Random xy=new Random(); boolean result=true; int i=0; do{ int x=xy.nextInt(25); if(i<leishu){ if(a[x]!=-1){ a[x]=-1; i++; } } if(i==leishu){ result=false; } }while(result); for(int j=0;j<a.length;j++){ if(a[j]==-1){ b[j/5][j%5]=-1; } } for(int j=0;j<5;j++){ for(int k=0;k<5;k++){ int all=0; if(b[j][k]!=-1){ if(j>0&&k>0){ if(b[j-1][k-1]==-1){ all++; } } if(j>0){ if(b[j-1][k]==-1){ all++; } } if(j>0&&k+1<5){ if(b[j-1][k+1]==-1){ all++; } } if(k>0){ if(b[j][k-1]==-1){ all++; } } if(k+1<5){ if(b[j][k+1]==-1){ all++; } } if(j+1<5&&k>0){ if(b[j+1][k-1]==-1){ all++; } } if(j+1<5){ if(b[j+1][k]==-1){ all++; } } if(j+1<5&&k+1<5){ if(b[j+1][k+1]==-1){ all++; } } b[j][k]=all; } } } lei1.setLabel(" ");lei2.setLabel(" ");lei3.setLabel(" ");lei4.setLabel(" "); lei5.setLabel(" ");lei6.setLabel(" ");lei7.setLabel(" ");lei8.setLabel(" "); lei9.setLabel(" ");lei10.setLabel(" ");lei11.setLabel(" ");lei12.setLabel(" "); lei13.setLabel(" ");lei14.setLabel(" ");lei15.setLabel(" ");lei16.setLabel(" "); lei17.setLabel(" ");lei18.setLabel(" ");lei19.setLabel(" ");lei20.setLabel(" "); lei21.setLabel(" ");lei22.setLabel(" ");lei23.setLabel(" ");lei24.setLabel(" "); lei25.setLabel(" "); e1=0;e2=0;e3=0;e4=0;e5=0;e6=0;e7=0;e8=0;e9=0;e10=0;e11=0;e12=0;e13=0;e14=0;e15=0;e16=0;e17=0;e18=0;e19=0;e20=0;e21=0;e25=0;e22=0;e23=0;e24=0; ss=1; shu=0; start.setLabel("重新开始"); tishi.setText(" "); time.setText(" 0秒 "); miao=-1; bz=true; } if(event.getSource()==exit){ System.exit(0); } if(event.getSource()==lei1){ if(ss==1){ if(e1==0){ if(b[0][0]==-1){ lei1.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei1.setLabel(" "+b[0][0]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e1=1; } } } if(event.getSource()==lei2){ if(ss==1){ if(e2==0){ if(b[0][1]==-1){ lei2.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei2.setLabel(" "+b[0][1]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e2=1; } } } if(event.getSource()==lei3){ if(ss==1){ if(e3==0){ if(b[0][2]==-1){ lei3.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei3.setLabel(" "+b[0][2]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e3=1; } } } if(event.getSource()==lei4){ if(ss==1){ if(e4==0){ if(b[0][3]==-1){ lei4.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei4.setLabel(" "+b[0][3]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e4=1; } } } if(event.getSource()==lei5){ if(ss==1){ if(e5==0){ if(b[0][4]==-1){ lei5.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei5.setLabel(" "+b[0][4]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e5=1; } } } if(event.getSource()==lei6){ if(ss==1){ if(e6==0){ if(b[1][0]==-1){ lei6.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei6.setLabel(" "+b[1][0]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e6=1; } } } if(event.getSource()==lei7){ if(ss==1){ if(e7==0){ if(b[1][1]==-1){ lei7.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei7.setLabel(" "+b[1][1]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e7=1; } } } if(event.getSource()==lei8){ if(ss==1){ if(e8==0){ if(b[1][2]==-1){ lei8.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei8.setLabel(" "+b[1][2]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e8=1; } } } if(event.getSource()==lei9){ if(ss==1){ if(e9==0){ if(b[1][3]==-1){ lei9.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei9.setLabel(" "+b[1][3]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e9=1; } } } if(event.getSource()==lei10){ if(ss==1){ if(e10==0){ if(b[1][4]==-1){ lei10.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei10.setLabel(" "+b[1][4]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e10=1; } } } if(event.getSource()==lei11){ if(ss==1){ if(e11==0){ if(b[2][0]==-1){ lei11.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei11.setLabel(" "+b[2][0]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e11=1; } } } if(event.getSource()==lei12){ if(ss==1){ if(e12==0){ if(b[2][1]==-1){ lei12.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei12.setLabel(" "+b[2][1]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e12=1; } } } if(event.getSource()==lei13){ if(ss==1){ if(e13==0){ if(b[2][2]==-1){ lei13.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei13.setLabel(" "+b[2][2]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e13=1; } } } if(event.getSource()==lei14){ if(ss==1){ if(e14==0){ if(b[2][3]==-1){ lei14.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei14.setLabel(" "+b[2][3]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e14=1; } } } if(event.getSource()==lei15){ if(ss==1){ if(e15==0){ if(b[2][4]==-1){ lei15.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei15.setLabel(" "+b[2][4]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e15=1; } } } if(event.getSource()==lei16){ if(ss==1){ if(e16==0){ if(b[3][0]==-1){ lei16.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei16.setLabel(" "+b[3][0]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e16=1; } } } if(event.getSource()==lei17){ if(ss==1){ if(e17==0){ if(b[3][1]==-1){ lei17.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei17.setLabel(" "+b[3][1]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e17=1; } } } if(event.getSource()==lei18){ if(ss==1){ if(e18==0){ if(b[3][2]==-1){ lei18.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei18.setLabel(" "+b[3][2]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e18=1; } } } if(event.getSource()==lei19){ if(ss==1){ if(e19==0){ if(b[3][3]==-1){ lei19.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei19.setLabel(" "+b[3][3]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e19=1; } } } if(event.getSource()==lei20){ if(ss==1){ if(e20==0){ if(b[3][4]==-1){ lei20.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei20.setLabel(" "+b[3][4]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e20=1; } } } if(event.getSource()==lei21){ if(ss==1){ if(e21==0){ if(b[4][0]==-1){ lei21.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei21.setLabel(" "+b[4][0]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e21=1; } } } if(event.getSource()==lei22){ if(ss==1){ if(e22==0){ if(b[4][1]==-1){ lei22.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei22.setLabel(" "+b[4][1]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e22=1; } } } if(event.getSource()==lei23){ if(ss==1){ if(e23==0){ if(b[4][2]==-1){ lei23.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei23.setLabel(" "+b[4][2]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e23=1; } } } if(event.getSource()==lei24){ if(ss==1){ if(e24==0){ if(b[4][3]==-1){ lei24.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei24.setLabel(" "+b[4][3]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e24=1; } } } if(event.getSource()==lei25){ if(ss==1){ if(e25==0){ if(b[4][4]==-1){ lei25.setLabel(" 雷 "); ss=0; bz=false; tishi.setText(" 哦,被炸死了 "); }else{ lei25.setLabel(" "+b[4][4]+" "); shu++; if(shu==25-leishu){ tishi.setText(" 哦,你赢了! "); ss=0; shu=0; bz=false; } } e25=1; } } } } public static void main(String args[]){ if(SaoLei.sl==null){ sl=new SaoLei("魏振松的扫雷游戏"); } sl.setView(); if(SaoLei.slr==null){ slr=new SaoLeiRunnable(sl); } if(SaoLei.t==null){ t=new Thread(slr); t.start(); } } }

微信网友_7558124162764800 LV2
6月18日
张德志 LV9
2023年12月27日
jiemomo LV12
2023年10月19日
选了了 LV7
2021年12月14日
ꪜiρ LV1
2021年11月5日
dkgxan LV1
2021年8月18日
hong1577271912 LV1
2021年8月15日
miaosen LV1
2021年6月25日
pipichao LV6
2021年6月24日
awdawd LV1
2021年6月21日

微信网友_7558124162764800 LV2
6月18日
1214783085 LV1
6月17日
13605416728 LV5
2024年12月13日
张德志 LV9
2023年12月27日
zhihong fan LV2
2023年12月26日
lshlsh
2023年12月25日
暂无贡献等级
bangyiyang LV2
2023年12月21日
jiemomo LV12
2023年10月19日
fenghuijun LV26
2023年3月27日
wdasfgas
2022年11月27日
暂无贡献等级