首页 > Java > JAVA扫雷小游戏源码免费下载

JAVA扫雷小游戏源码免费下载

上一篇 下一篇
 
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);     
    }
}
 

模板简介:该模板名称为【JAVA扫雷小游戏源码免费下载】,大小是,文档格式为.,推荐使用打开,作品中的图片,文字等数据均可修改,图片请在作品中选中图片替换即可,文字修改直接点击文字修改即可,您也可以新增或修改作品中的内容,该模板来自用户分享,如有侵权行为请联系网站客服处理。欢迎来懒人模板【Java】栏目查找您需要的精美模板。

  • 下载密码 lanrenmb
  • 下载次数 11,815次
  • 使用软件
  • 文件格式
  • 文件大小
  • 上传时间 08-07
  • 作者 网友投稿
  • 肖像权 人物画像及字体仅供参考
栏目分类 更多 >
热门推荐 更多 >
微信图片 微信模板 html5 微信公众平台 响应式 微信素材 企业网站 自适应 单页式简历模板 微信文章
您可能会喜欢的其他模板