failgame.setText(\扫雷\\\);
//如果输了后还有没有揭开内容的button,则全部揭开内容,用到2
层for循环遍历Button_Game数组
for(int a=0;a for(int b=0;b if(Button_Game[a][b].getText().equals(new String(\))){ 应 //如果玩家在该button标记了flag if(Map_Bomb[a][b]!=9){ //被玩家标记错了,显示wrong图标 Button_Game[a][b].setImage(imagesource.wrong); } else if(Map_Bomb[a][b]==9){ //被玩家标记对了,显示explosion图标 Button_Game[a][b].setImage(imagesource.explosion); } } } else sweep(a,b); } int response=failgame.open(); //开启对话框,等待玩家响 if(response==SWT.YES){ //如果点击确定,则退出 dialog } //判断是否赢,如果格子全部被设置了图片,且mineborder.success是true,则赢了 17 } } } } System.exit(0); return; int x=0,y=0; for(x=0;x } for(y=0;y if(Button_Game[x][y].getImage()!=null){ } else return; continue; if(x==Bomb_I&&(y==Bomb_J)&&(minesweeper.swt.mineborder.Tag_Num==0)){ minesweeper.swt.mineborder.timer.cancel(); System.out.println(\你获胜成绩: \+minesweeper.swt.mineborder.CountTime); //如果获胜,并且成绩更新了英雄榜的成绩,则弹出英雄榜,让玩家输入大名! try { hero hg=new hero(); //构造函数初始化hero类 } catch (IOException e1) { } if(hero.scorecompare()){ //用scorecompare函数查看是否应该弹出 e1.printStackTrace(); 影响榜,即比较玩家成绩和对应难度的历史成绩 } //弹出 “你赢了”对话框 MessageBox failgame=new hero.herodiag(Button_Game[0][0].getParent().getShell()); try { hero.sethighscore(); //更新英雄榜成绩! } catch (IOException e1) { } e1.printStackTrace(); MessageBox(Button_Game[0][0].getParent().getShell(),SWT.ICON_QUESTION|SWT.YES); 18 } } } failgame.setMessage(\你赢了\); failgame.setText(\扫雷\\\); int response=failgame.open(); //开启该对话框 if(response==SWT.YES) System.exit(0); //如果点击确定,则退出dialog } (3) MouseRightListener类 package minesweeper.action; import java.io.IOException; import java.util.TimerTask; import minesweeper.swt.*; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.*; import org.eclipse.swt.events.*; //创建右键点击触发的MouseAdapter public class MouseRightListener extends MouseAdapter{ private Button [][]Button_Game; private int[][]Map_Bomb; private int Bomb_I,Bomb_J; private ImageSource imagesource=new ImageSource(mainshell.d); //构造函数,用于初始化参数,便于后续进行操作 public MouseRightListener(Button[][]Button_Game,int[][]Map_Bomb,int Bomb_I,int Bomb_J){ } 19 this.Button_Game=Button_Game; this.Map_Bomb=Map_Bomb; this.Bomb_I=Bomb_I; this.Bomb_J=Bomb_J; //创建鼠标右键点击事件函数 public void mouseUp(MouseEvent e) { if(e.button==3){ //判断是否是鼠标右键点击 //获取该点击区域的对象 Object Button_Select=e.getSource(); if(minesweeper.swt.fuzhumianbanComposite.FirstClickFlag){ //如果是第一次点击,启动时钟 minesweeper.swt.fuzhumianbanComposite.FirstClickFlag=false; TimerTask task=new CountT(minesweeper.swt.fuzhumianbanComposite.l2); } for(int i=0;i for(int j=0;j if(Button_Select==Button_Game[i][j]){ minesweeper.swt.mineborder.timer.schedule(task, 0,1000); //2层for循环查找选择的按钮的i,j坐标 //如果该坐标的button没有被翻开,且还有足够的flag可以让你设置,则 设置该button为flag if(Button_Game[i][j].getImage()==null&&(minesweeper.swt.mineborder.Tag_N um>=1)) { Button_Game[i][j].setImage(imagesource.flag); // 设置该button为flag Button_Game[i][j].setText(\); // minesweeper.swt.mineborder.Tag_Num--; 对应可用的flag数Tag_Num减一 fuzhumianbanComposite.l1.setText(Integer.toString(minesweeper.swt.minebo rder.Tag_Num)); } //如果该坐标的button设置为flag,这取消设置 else if(Button_Game[i][j].getText().equals(new String(\))){ Button_Game[i][j].setText(\); Button_Game[i][j].setImage(null); 20 minesweeper.swt.mineborder.Tag_Num++; // 对应可用的flag数Tag_Num加一 fuzhumianbanComposite.l1.setText(Integer.toString(minesweeper.swt.minebo rder.Tag_Num)); if(i==Bomb_I&&j==Bomb_J&&(minesweeper.swt.mineborder.Tag_Num==0)){ minesweeper.swt.mineborder.timer.cancel(); System.out.println(\你获胜成绩: } //判断是否赢,如果格子全部被设置了图片,且mineborder.success是true,则赢了 int i=0,j=0; for(i=0;i for(j=0;j if(Button_Game[i][j].getImage()!=null){ } else return; continue; } } } \+minesweeper.swt.mineborder.CountTime); //如果获胜,并且成绩更新了英雄榜的成绩,则弹出英雄榜,让玩家输入大名! try { hero hg=new hero(); } catch (IOException e1) { } if(hero.scorecompare()){ //用scorecompare函数查看是否应该弹 e1.printStackTrace(); 出影响榜,即比较玩家成绩和对应难度的历史成绩 hero.herodiag(Button_Game[0][0].getParent().getShell()); 21 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库java课程设计 SWT 扫雷(功能图,类图,类详细说明,测试)(5)在线全文阅读。
相关推荐: