小游戏:扫雷

来源:原创作者:编辑:admin2020-02-09 23:42

  package test;

  import java.awt.BorderLayout;

  import java.awt.Color;

  import java.awt.Container;

  import java.awt.GridLayout;

  import java.awt.Insets;

  import java.awt.Label;

  import java.awt.event.ActionEvent;

  import java.awt.event.ActionListener;

  import java.awt.event.ItemEvent;

  import java.awt.event.ItemListener;

  import java.awt.event.MouseEvent;

  import java.awt.event.MouseListener;

  import java.util.Random;

  import javax.swing.JButton;

  import javax.swing.JComboBox;

  import javax.swing.JFrame;

  import javax.swing.JOptionPane;

  import javax.swing.JPanel;

  public class SaoLei implements MouseListener,ActionListener{

  JPanel p=new JPanel();

  JFrame frame =new JFrame("365bet");

  @SuppressWarnings("rawtypes")

  JComboBox combobox =new JComboBox();

  JButton reset =new JButton("从新末尾");

  Container container =new Container();

  //游戏数据结构

  SaoLeiConstant constant=new SaoLeiConstant();

  JButton[][] buttons =new JButton[constant.row][constant.col];//定义按钮

  int[][] counts=new int [constant.row][constant.col];//定义整型数组保管按钮下方雷数

  //创立结构方法

  public SaoLei() {

  //显示窗口

  frame.setSize(600,700);//600*700

  frame.setResizable(false);

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  frame.setLayout(new BorderLayout());

  //添减轻来、选择难度按钮

  addtopButton();

  //添加雷区按钮

  addButtons();

  //埋雷

  addLei();

  //添加雷的计数

  calcNeiboLei();

  frame.setVisible(true);

  }

  void addtopButton() {

  p.removeAll();

  p.add(reset);

  reset.setBackground(Color.green);

  reset.setOpaque(true);

  reset.addActionListener(this);

  //combobox.addItem("选择难度");

  combobox.addItem("新手难度");

  combobox.addItem("低级难度");

  combobox.addItem("中级难度");

  combobox.addItem("低级难度");

  combobox.addItem("巨匠难度");

  combobox.setBackground(Color.GREEN);

  combobox.setOpaque(true);

  combobox.addItemListener(new ItemListener(){

  @Override

  public void itemStateChanged(ItemEvent e) {

  String item = e.getItem().toString();

  if(item=="新手难度") {

  constant.leiCount =20;