信息与计算科学0601王丹平060701024
+ priviousPoint.getJ();
int index2 = currPoint.getI() * (Settings.COLUMNS + 2)
+ currPoint.getJ();
chesses[index1].setVisible(false); chesses[index2].setVisible(false);
// 如果棋子总数已为0,则程序结束 } /**
* 事件监听器处理函数,也是处理棋子消除的地方 */
public void actionPerformed(ActionEvent e){ // 获得当前的柜子
ChessButton button = (ChessButton) e.getSource(); // 获得当前棋子的数据结构
ArrayPoint p = button.getPoint(); // 如果已有两个棋子选中, 则进行判断操作 if (two){
currPoint = p;
if( map.match(this.priviousPoint, this.currPoint)){ }
// 设置为没有两个按钮的选中的状态 two = false;
clearCheese(this.priviousPoint, this.currPoint); if (map.LEFTCOUNT == 0){ }
JOptionPane.showMessageDialog(this, \恭喜您通过!!\
9
信息与计算科学0601王丹平060701024
} else { } }
//炸弹的功能 public void bomb(){
int[][] values = map.getMap(); ArrayPoint p1 = null; ArrayPoint p2 = null;
for (int row = 1; row < Settings.ROWS + 1; row++){
for (int col = 1; col < Settings.COLUMNS + 1; col++){
if (values[row][col] != 0){
p1 = new ArrayPoint(row, col, values[row][col]); for (int i = 1; i < Settings.ROWS + 1; i++){
for (int j = 1; j < Settings.COLUMNS + 1; j++){
if (values[i][j] != 0){ } else {
continue;
p2 = new ArrayPoint(i, j, values[i][j]);
// 将当前点击的棋子赋给变量priviousPoint this.priviousPoint = p;
// 标志位设为TRUE,用于点击下个棋子的时候使用 two = true;
10
信息与计算科学0601王丹平060701024
}
}
}
}
}
}
if (map.match(p1, p2)){ }
clearCheese(p1, p2); return;
} }
********************************************************** * 类名: ChessButton
* 作用: 初始化游戏中鼠标点击按钮* * 继承的父类: JButton类 * * 实现的接口: 没有 *
********************************************************** import java.net.*; import javax.swing.*; import cn.elva.Settings;
import cn.elva.model.ArrayPoint;
public class ChessButton extends JButton{
protected ArrayPoint point = null;
public ChessButton(int row, int col, int value){ this(new ArrayPoint(row, col, value));
11
信息与计算科学0601王丹平060701024
}
public ChessButton(ArrayPoint point){ this.point = point;
String name =\ URL url = ChessButton.class.getResource(name); ImageIcon icon = new ImageIcon( url ); this.setIcon(icon); }
//构造函数,使用默认值 public ChessButton(){
this(new ArrayPoint(0, 0, 0)); }
//返回当前按钮代表的位置和值
}
public ArrayPoint getPoint(){ return point; }
public void setPoint(ArrayPoint point){ this.point = point; }
********************************************************** * 接口名:Settings* * 作用: 声明各个变量大小*
**********************************************************
package cn.elva;
public interface Settings{
12
信息与计算科学0601王丹平060701024
//行数
public static final int ROWS = 8; //列数 }
public static final int COLUMNS=8; //图片后缀名
public static final String RELEX=\//每局所花时间(秒)
public static final int PERTIME = 600; //判断的时间间隔
public static final int PER = 1; //炸弹的使用次数
public static final int BOMBCOUNT = 3;
**********************************************************
package cn.elva.model; import java.util.Random; import cn.elva.Settings; public class Map {
public static int LEFTCOUNT = Settings.ROWS * Settings.COLUMNS; // 让其最外层的数据不显示,可以解决边框消除不掉的情况
private int[][] map = new int[Settings.ROWS + 2][Settings.COLUMNS + * 类名: Map
* 作用: 连入图片并声明游戏规则*
**********************************************************
2];
13