package boomplay;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class BoomButton extends JButton{
boolean isBoom; //是否是炸弹
int arrowBoom; //如果不是炸弹,周围的炸弹个数
int x,y;
boolean open;
BoomButton(){//构造函数
super();
//添加鼠标监听事件
this.setMargin(new Insets(0,0,0,0));//设置边缘为空,正常显示button内容
this.open=false;
this.isBoom=false;//全部不是雷
this.setSize(30,30);//设置方块大小
this.setPreferredSize(new Dimension(30,30));
this.setVisible(true);
this.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
if(true)
{ //左键
if(isBoom){
//游戏结束代码
showBoom();
JOptionPane.showMessageDialog(null,"啊哦!你踩到雷了!","游戏结束",JOptionPane.INFORMATION_MESSAGE);
}else{
//该处不是炸弹,显示该块个数代码
if(arrowBoom==0)
{
cleanNoneBoomBut(x,y,HardGameFra.bb);
}else{
showArountBoom();
}
setEnabled(false);
}
}
else if(false)
{
//用户输入右键,标记为是雷的代码
}
}
});
}
void showBoom(){
this.setBackground(Color.red);
this.setText("雷");
}
void shakBoom(){
this.setText("!");
}
void showArountBoom(){
if(!isBoom)
this.setText(Integer.toString(arrowBoom));
}
void setIsBoom(){//创建新游戏时,设定是不是方块
isBoom=true;
}
void cleanNoneBoomBut(int i,int j,BoomButton bb[][]){
bb[i][j].open=true;
if(i!=0&&j!=0){//左上角
if(bb[i-1][j-1].arrowBoom==0&&!bb[i-1][j-1].open){
bb[i-1][j-1].cleanNoneBoomBut((i-1),(j-1),bb);
//bb[i-1].[j].showAr
//bb[i-1][j-1].setEnabled(false);
}
}
if(i!=0){ //正上方
if(bb[i-1][j].arrowBoom==0&&!bb[i-1][j].open){
bb[i-1][j].cleanNoneBoomBut((i-1),(j),bb);
//bb[i-1][j].showArountBoom();
//bb[i-1][j].setEnabled(false);
}
}
if(i!=0&&j!=29){//右上方
if(bb[i-1][j+1].arrowBoom==0&&!bb[i-1][j+1].open){
bb[i-1][j+1].cleanNoneBoomBut((i-1),(j+1),bb);
//bb[i-1][j+1].showArountBoom();
//bb[i-1][j+1].setEnabled(false);
}
}
if(j!=29){ //正右边
if(bb[i][j+1].arrowBoom==0&&!bb[i][j+1].open){
bb[i][j+1].cleanNoneBoomBut((i),(j+1),bb);
//bb[i][j+1].showArountBoom();
//bb[i][j+1].setEnabled(false);
}
}
if(i!=19&&j!=29){//右下方
if(bb[i+1][j+1].arrowBoom==0&&!bb[i+1][j+1].open){
bb[i+1][j+1].cleanNoneBoomBut((i+1),(j+1),bb);
//bb[i+1][j+1].showArountBoom();
//bb[i+1][j+1].setEnabled(false);
}
}
if(i!=19){ //正下方
if(bb[i+1][j].arrowBoom==0&&!bb[i+1][j].open){
bb[i+1][j].cleanNoneBoomBut((i+1),(j),bb);
//bb[i+1][j].showArountBoom();
//bb[i+1][j].setEnabled(false);
}
}
if(i!=19&&j!=0){ //左下方
if(bb[i+1][j-1].arrowBoom==0&&!bb[i+1][j-1].open){
bb[i+1][j-1].cleanNoneBoomBut((i+1),(j-1),bb);
//bb[i+1][j-1].showArountBoom();
//bb[i+1][j-1].setEnabled(false);
}
}
if(j!=0){ //正左方
if(bb[i][j-1].arrowBoom==0&&!bb[i][j-1].open){
bb[i][j-1].cleanNoneBoomBut((i),(j-1),bb);
//bb[i][j-1].showArountBoom();
//bb[i][j-1].setEnabled(false);
}
}
bb[i][j].showArountBoom();
bb[i][j].setEnabled(false);
}
}