欢迎来到天天文库
浏览记录
ID:19616412
大小:56.50 KB
页数:19页
时间:2018-10-04
《java扫雷程序(完整)》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、java扫雷程序(完整)JAVA编程的扫雷小游戏的源代码importjava.awt.event.*;importjava.awt.*;importjavax.swing.*;importjava.util.*;importjava.io.*;publicclassMineSquareextendsJPanelimplementsMouseListener{introws=10,cols=10,雷数=10;JButtonbuttonFace=null;Blockblock[][];TimeCounttime;CountMinecount;Stringgrade=
2、null;RandomSetMine随机布雷者;FindAroundMineNumber确定周围雷数者;FindSafeArea找出无雷连通区者;DetermineDigArea成片挖开者;DetermineMineMarkIsRightOrWrong确定雷标记是否正确者;FindAroundMineMarkNumber确定周围雷标数目者;DecideWinner判断是否胜利者;Record记录对话框=null;publicMineSquare(Stringgrade,intmineNumber,introws,intcols,JButtonb,JDialogd
3、ialog){this.grade=grade;this.rows=rows;this.cols=cols;雷数=mineNumber;判断是否胜利者=newDecideWinner();记录对话框=(Record)dialog;block=newBlock[rows+1][cols+1];buttonFace=b;time=newTimeCount();count=newCountMine(雷数);count.textShowMine.setText(""+雷数);setLayout(newGridLayout(rows,cols));http://downl
4、oad.csdn.net/source/955155Importjavax.swing.ImageIcon;//程序入口publicclassBlock{Stringname;//名字,比如"雷"或数字intaroundMineNumber;//周围雷的数目ImageIconmineIcon;//雷的图标booleanisMine=false;//是否是雷booleanisMark=false;//是否被标记booleanisOpen=false;//是否被挖开publicvoidsetName(Stringname){this.name=name;}//设置周
5、围的雷数publicvoidsetAroundMineNumber(intn){aroundMineNumber=n;}//获得周围的雷数publicintgetAroundMineNumber(){returnaroundMineNumber;}publicStringgetName(){returnname;}//判断是否是雷publicbooleanisMine(){returnisMine;}//设置是否为雷publicvoidsetIsMine(booleanb){isMine=b;}//设置雷的图标publicvoidsetMineIcon(Imag
6、eIconicon){mineIcon=icon;}//获得雷的图标publicImageIcongetMineicon(){returnmineIcon;}//确定雷是否被挖开publicbooleangetIsOpen(){returnisOpen;}//设置为已经被挖开publicvoidsetIsOpen(booleanp){isOpen=p;}//返回此处是否已经被标记publicbooleangetIsMark(){returnisMark;}//设置此处是否已经被标记publicvoidsetIsMark(booleanm){isMark=m;}i
7、mportjavax.swing.*;importjava.awt.*;publicclassBlockViewextendsJPanel{JLabelblockNameOrIcon;//用来显示Block对象的name、number和mineIcon属性JButtonblockCover;//用来遮挡blockNameOrIcon.CardLayoutcard;//卡片式布局BlockView(){card=newCardLayout();setLayout(card);blockNameOrIcon=newJLabel("",JLabel.CENTER);b
8、lockNameOrIc
此文档下载收益归作者所有