⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sfram.java

📁 JAVA扫雷小游戏,希望对大家有所帮助
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class SFram extends JPanel{
	private int showLeave=10;
	private int realLeave=10;
	private JPanel[][] lei;
	private int ge;
	MediaTracker mt=new MediaTracker(this);
	private Saolei saolei;
	SFram(int ge,Saolei saolei){
		this.saolei=saolei;
		this.ge=ge;
		replay(ge,10);
	}
	SFram(Saolei saolei){
		this.saolei=saolei;
		this.ge=9;
		replay(ge,10);
	}
	public void replay(int ge,int mlei){
		showLeave=mlei;
		realLeave=mlei;
		this.removeAll();
		this.setLayout(new GridLayout(ge,ge,1,1));
		lei=new JPanel[ge][ge];
		for(int i=0;i<ge;i++){
			for(int j=0;j<ge;j++){
				lei[i][j]=new JPanel();
				lei[i][j].setBackground(Color.decode("#999999"));
				lei[i][j].add(new JLabel(""));
				lei[i][j].addMouseListener(new MouseRead(i,j,saolei));
				this.add(lei[i][j]);
				//lei[i][j].createImage(40,40);
				lei[i][j].setSize(10,10);
			}
		}
		//this.setSize(500,500);
	}
	public boolean setOpen(int x,int y,int z){
		if(lei[x][y].getName()!="leibiao"){	
			if(z==0){
				lei[x][y].removeAll();
				lei[x][y].setBackground(Color.decode("#cccccc"));
				saolei.reshow();
			}
			else if(z==9){	
				lei[x][y].removeAll();
				lei[x][y].add(new JLabel("雷"));
				lei[x][y].setBackground(Color.decode("#ff0000"));
				saolei.reshow();
			}
			else if(z<9&&z>0){
				lei[x][y].removeAll();
				lei[x][y].add(new JLabel(""+z+""));
				lei[x][y].setBackground(Color.decode("#cccccc"));
				saolei.reshow();
			}
			lei[x][y].setName("open");
			return true;
		}
		else
			return false;
	}
	public void setClose(int x,int y,int z){
		if(lei[x][y].getName()!="open"){
			if(lei[x][y].getName()!="leibiao"){
				lei[x][y].removeAll();
				lei[x][y].add(new JLabel("注"));
				lei[x][y].setBackground(Color.decode("#cccc00"));
				lei[x][y].setName("leibiao");
				showLeave--;
				if(z==1){
					realLeave--;
					if(realLeave==0)
						saolei.win();
				}
				saolei.reshow();
			}
			else{
				lei[x][y].removeAll();
				lei[x][y].setBackground(Color.decode("#999999"));
				lei[x][y].setName(null);
				showLeave++;
				if(z==1)
					realLeave++;
				saolei.reshow();
			}
		}
	}
	public int getShowLeave(){
		return showLeave;
	}
	//void setBlank(int x,int y){
	//	if(lei[x][y])
	//}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -