java 简单的扫雷游戏

2020-11-23 08:57

阅读:570

标签:扫雷游戏   java   

//扫雷游戏
package Bible001;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Mine extends MouseAdapter {

	private JFrame mainFrame;
	private int[][] data;
	private JButton[][] buttons;
	private JButton startJB;
	private Label l;
	private int row;
	private int col;
	private int mineNumber;
	private int mineCount;
	private boolean isOver;
	public Mine(){
		row=15;
		col=15;
		mainFrame=new JFrame("扫雷v1.0");
		data=new int[row][col];
		buttons=new JButton[row][col];
		startJB=new JButton("Start");
		l=new Label("welcome to mine!");
		mineNumber=row*col/7;
	}
	public void init(){
		JPanel north=new JPanel();
		JPanel center=new JPanel();
		JPanel south=new JPanel();
		north.setLayout(new FlowLayout());
		center.setLayout(new FlowLayout());
	 
		south.setLayout(new GridLayout(row,col,4,4));
		mainFrame.setLayout(new BorderLayout());
		mainFrame.add(north,BorderLayout.NORTH);
		mainFrame.add(center,BorderLayout.CENTER);
		mainFrame.add(south, BorderLayout.SOUTH);
		north.add(l);
		startJB.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				for(int i=0;i=0&&j+n>=0&&i+m=mineNumber){
		 		 System.out.println(mineNumber);
		 		 l.setText("^_^");
		 	 }
		}
	}
	public void mousePressed(MouseEvent e){
		try{
			if(isOver)
				return;
			if(e.getButton()==MouseEvent.BUTTON3){
				JButton jb=(JButton)e.getSource();
				if(jb.getText().equals("M")){
					jb.setText(" ");
					mineCount--;
					jb.setBackground(Color.white);
				}else{
					if(mineCount=0&&j+n>=0&&i+m

java 简单的扫雷游戏

标签:扫雷游戏   java   

原文地址:http://blog.csdn.net/huolei_blog/article/details/24599871


评论


亲,登录后才可以留言!