77范文网 - 专业文章范例文档资料分享平台

java课程设计 SWT 扫雷(功能图,类图,类详细说明,测试)(5)

来源:网络收集 时间:2018-12-03 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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)在线全文阅读。

java课程设计 SWT 扫雷(功能图,类图,类详细说明,测试)(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/333983.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: