java连连看小游戏

article/2025/9/28 23:10:28

目录

运行界面图

代码如下(示例):

2.运行演示


这是一个用java编写的小游戏,连连看是一种消除类益智游戏,核心要求是在规定的时间内,消除游戏界面中选中的两张相同的图案,直至完全消除所有图案。这款游戏操作简单(只需单击鼠标左键操作)、面向人群广泛,在限时操作的游戏要求下,吸引玩家自发地锻炼观察能力、判断能力和反应能力,故从推出至今颇受欢迎。


提示:以下是本篇文章正文内容,下面案例可供参考

运行界面图

代码如下(示例)

package ui;import java.awt.Choice;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;public class Llk_2 extends JFrame {private static final long serialVersionUID = 1L;public Llk_2() {LianLianKanJPanel llk = new LianLianKanJPanel();add(llk);}class LianLianKanJPanel extends JPanel implements ActionListener,ItemListener {private static final long serialVersionUID = 1L;//序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性。private int[][] map = new int[8][8];//8*8的正方形private int kind, randomx, randomy, randomx1, randomy1; // 种类,随机xprivate int coordinatex, coordinatey, coordinatex1, coordinatey1; // 坐标Xprivate Point lineStart = new Point(0, 0);private int clicktimes;private int jishushengyu;//计数剩余private int Kinds = 4;private int score;private int guanshu;//关数loudou ld = new loudou();// 漏斗JButton BlockButton[][] = new JButton[8][8];//Choice difficultChoice = new Choice();JButton newgameButton = new JButton("重新开始");JButton reLoad = new JButton("刷新");ImageIcon ii = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/bjt2.jpeg");ImageIcon aIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/1.jpg");ImageIcon bIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/2.jpg");ImageIcon cIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/3.gif");ImageIcon dIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/4.gif");ImageIcon eIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/5.jpg");ImageIcon fIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/6.gif");ImageIcon gIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/7.jpeg");ImageIcon hIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/8.jpeg");ImageIcon iIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/9.jpeg");ImageIcon jIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/10.jpeg");ImageIcon kIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/13.jpg");ImageIcon lIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/11.jpeg");ImageIcon mIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/12.jpeg");ImageIcon nIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/5.jpg");ImageIcon oIcon = new ImageIcon("C:\\Users\\zjjt\\Desktop\\sb/6.gif");public LianLianKanJPanel() {this.setLayout(null);newMap();for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {BlockButton[i][j] = new JButton();add(BlockButton[i][j]);BlockButton[i][j].addActionListener(this);//监听器BlockButton[i][j].setBounds(30 + j * 40, 30 + i * 40, 31,34);//	BlockButton[i][j].setBorderPainted(false);//  BlockButton[i][j].setVisible(true);}}difficultChoice.add("简单");difficultChoice.add("中等");difficultChoice.add("困难");difficultChoice.add("变态");newgameButton.setBounds(map[0].length * 40 + 80, 40, 100, 20);newgameButton.setBackground(Color.white);newgameButton.setBorderPainted(false); //去边框reLoad.setBounds(map[0].length * 40 + 100, 80, 60, 20);reLoad.setBackground(Color.white);reLoad.setBorderPainted(false);difficultChoice.setBounds(map[0].length * 40 + 100, 120, 60, 20);difficultChoice.addItemListener(this);newgameButton.addActionListener(this);reLoad.addActionListener(this);this.add(newgameButton);this.add(reLoad);this.add(difficultChoice);// /-------------------------漏斗ld.setBounds(map[0].length * 40 + 100, 200, 70, 150);// 漏斗ld.setBackground(Color.black);this.add(ld);}class loudou extends JPanel implements Runnable {private static final long serialVersionUID = 1L;private int dijiguan;int remainTimes = 0; // 时间int x1 = 0;int y1 = 30;int x2 = 60;int y2 = 150;Thread nThread1;//线程JLabel overJLabel = new JLabel();JDialog dialog = new JDialog();public loudou() {nThread1 = new Thread(this);				nThread1.start();this.setLayout(null);this.add(overJLabel);overJLabel.setBounds(0, 0, 200, 50);overJLabel.setForeground(Color.white);}public void setdijiguan(int x) {this.dijiguan = x;}public void paintComponent(Graphics g) // 画画函数{super.paintComponent(g);g.setColor(Color.green);for (int i = 0; i < 56; i++) {g.drawLine(x1 + i / 2 + 2, y1 + i, x2 - i / 2 - 2, y1 + i);}if (remainTimes < 55) {for (int i = 0; i < remainTimes; i++) {g.drawLine(x1 + i / 2 + 2, y2 - i - 1, x2 - i / 2 - 2, y2 - i- 1);}g.drawLine((x1 + x2) / 2, (y1 + y2) / 2, (x1 + x2) / 2, y2 - 2);g.drawLine((x1 + x2) / 2 + 1, (y1 + y2) / 2 + 1, (x1 + x2) / 2 + 1,y2 - 2);//两条竖线g.setColor(getBackground());for (int i = 0; i < remainTimes; i++) {g.drawLine(x1 + i / 2 + 2, y1 + i, x2 - i / 2 - 2, y1 + i);//覆盖上边的倒三角}}if (remainTimes >= 50 && remainTimes <= 55)overJLabel.setText(55-remainTimes +"s");if (remainTimes == 56) overJLabel.setText("OVER");}public void setTimes(int x) {this.remainTimes = x;}public int getTimes() {return remainTimes;}public void run() {while (dijiguan < 20) {if (remainTimes == 0) {JOptionPane.showMessageDialog(null, "游戏开始?");}if (remainTimes == 56) {JOptionPane.showMessageDialog(null, "时间到!游戏结束!");}remainTimes++;repaint();try {if (dijiguan < 6)Thread.sleep(1500 - dijiguan * 100);if (dijiguan >= 6 && dijiguan <= 8)Thread.sleep(1000 - (dijiguan - 5) * 50);if (dijiguan > 8)Thread.sleep(850 - (dijiguan - 8) * 20);} catch (InterruptedException e) {e.printStackTrace();}}}}public void paintComponent(Graphics g) {super.paintComponent(g);//是父类JPanel里的方法,会把整个面板用背景色重画一遍,起到清屏的作用g.drawImage(ii.getImage(), 0, 0, this);//绘制两个文本字符串g.setColor(Color.white);g.drawString("得分: " + score, 430, 165);g.drawString("第 " + (guanshu + 1) + " 关", 430, 190);for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {switch (map[i][j]) {case 0:BlockButton[i][j].setVisible(false);break;case 1:BlockButton[i][j].setIcon(aIcon);break;case 2:BlockButton[i][j].setIcon(bIcon);break;case 3:BlockButton[i][j].setIcon(cIcon);break;case 4:BlockButton[i][j].setIcon(dIcon);break;case 5:BlockButton[i][j].setIcon(eIcon);break;case 6:BlockButton[i][j].setIcon(fIcon);break;case 7:BlockButton[i][j].setIcon(gIcon);break;case 8:BlockButton[i][j].setIcon(hIcon);break;case 9:BlockButton[i][j].setIcon(iIcon);break;case 10:BlockButton[i][j].setIcon(jIcon);break;case 11:BlockButton[i][j].setIcon(kIcon);break;case 12:BlockButton[i][j].setIcon(lIcon);break;case 13:BlockButton[i][j].setIcon(mIcon);break;case 14:BlockButton[i][j].setIcon(nIcon);break;case 15:BlockButton[i][j].setIcon(oIcon);break;default:break;}}}}//重载public void chongzai() {  jishushengyu = 0;for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {if (map[i][j] > 0) {jishushengyu++;}}}int[][] map1 = new int[8][8];this.map = map1;Random random = new Random();for (int i = 0; i < jishushengyu / 2; i++) {kind = random.nextInt(Kinds) + 1;//0~3+1  === 1~4do {				randomx1 = random.nextInt(8);//0-8随机数randomy1 = random.nextInt(8);} while (map[randomy1][randomx1] > 0);map[randomy1][randomx1] = kind;do {randomx = random.nextInt(8);randomy = random.nextInt(8);} while (map[randomy][randomx] > 0);map[randomy][randomx] = kind;	}	repaint();for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {BlockButton[i][j].setVisible(true);}}		}public void newGame() {// JOptionPane.showMessageDialog(null,"你按了开始按钮");for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {BlockButton[i][j].setEnabled(true);BlockButton[i][j].setVisible(true);}}int[][] map = new int[8][8];this.map = map;newMap();ld.setTimes(0);score = 0;guanshu = 0;ld.setdijiguan(guanshu);}public void guoguan() {int jishushengyu2 = 0;for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {if (map[i][j] > 0) {jishushengyu2++;}}}if (jishushengyu2 == 0) {for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {BlockButton[i][j].setEnabled(true);BlockButton[i][j].setVisible(true);}}int[][] map = new int[8][8];this.map = map;newMap();			ld.setTimes(0);guanshu++;ld.setdijiguan(guanshu);reLoad.setEnabled(true);}}public void newMap() {ArrayList<Integer> numbers = new ArrayList<Integer>();//链表for (int i = 0; i < Kinds; i++) {numbers.add(i + 1);//加到列表尾部numbers.add(i + 1);}//每一次重新布局的时候,能保证一定有前几种难度中的图片类型Random random = new Random();int temp = 0;for (int i = 0; i < 32- Kinds; i++) {temp = random.nextInt(Kinds) + 1;//0~kinds-1之间的随机数在加1numbers.add(temp);numbers.add(temp);}Collections.shuffle(numbers);//随机打乱原来的顺序map = new int[8][8];temp = 0;for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {//JOptionPane.showMessageDialog(null, numbers.get(temp));map[i][j] = numbers.get(temp++).intValue();//get方法返回第i个元素,intvalue 返回int类型				}}}public void itemStateChanged(ItemEvent e) {// TODO 自动生成的方法存根if (e.getSource() == difficultChoice) {String selected = difficultChoice.getSelectedItem();if (selected == "简单") {Kinds = 4;newGame();repaint();} else if (selected == "中等") {Kinds = 8;newGame();repaint();} else if (selected == "困难") {Kinds = 12;newGame();repaint();} else if (selected == "变态") {Kinds = 15;newGame();repaint();}}}public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根if (ld.getTimes() >56) {for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {BlockButton[j][i].setEnabled(false);}}}if (e.getSource() == reLoad) {chongzai();reLoad.setEnabled(false);}if (e.getSource() == newgameButton) {newGame();reLoad.setEnabled(true);}for (int i = 0; i < 8; i++) {for (int j = 0; j < 8; j++) {if (e.getSource() == BlockButton[j][i]) {clicktimes++; // 点击的次数lineStart.move(i, j);if (clicktimes % 2 == 1) {coordinatex1 = i;coordinatey1 = j;BlockButton[coordinatey1][coordinatex1].setEnabled(false);BlockButton[coordinatey][coordinatex].setEnabled(true);//	BlockButton[j][i].setEnabled(false);}if (clicktimes % 2 == 0) {coordinatex = i;coordinatey = j;BlockButton[coordinatey][coordinatex].setEnabled(false);BlockButton[coordinatey1][coordinatex1].setEnabled(true);}}}}this.requestFocus();clearBlock();/** for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) {* BlockButton[j][i].setEnabled(true); }* * }*/repaint();}// 判断在一列之内两图片之间是否全部是空白或直接相邻private boolean containsAllOrNoneZeroInColumn(int posX1, int posY1,int posX2, int posY2) {// 直接相连,因而不包含空白if (Math.abs(posY1 - posY2) == 0) {return true;}int a = posY1 < posY2 ? posY1 : posY2;int b = posY1 < posY2 ? posY2 : posY1;//y值:a小 b大for (int j = a + 1; j < b; j++) {if (map[posX1][j] != 0) {return false;}}return true;}// 判断在一行之内两图片之间是否全部是空白或直接相邻private boolean containsAllOrNoneZeroInRow(int posX1, int posY1,int posX2, int posY2) {// 直接相连,因而不包含空白if (Math.abs(posX1 - posX2) == 0) {return true;}int a = posX1 < posX2 ? posX1 : posX2;int b = posX1 < posX2 ? posX2 : posX1;for (int i = a + 1; i < b; i++) {if (map[i][posY1] != 0) {return false;}}return true;}// 是否可以一直线相连private boolean isLinkByOneLine(int posX1, int posY1, int posX2,int posY2) {if (posX1 != posX2 && posY1 != posY2) {return false;}if (posX1 == posX2) {if (containsAllOrNoneZeroInColumn(posX1, posY1, posX2, posY2)) {return true;}}if (posY1 == posY2) {if (containsAllOrNoneZeroInRow(posX1, posY1, posX2, posY2)) {return true;}}return false;}// 是否可以两直线相连private boolean isLinkByTwoLines(int posX1, int posY1, int posX2,int posY2) {if (posX1 != posX2 && posY1 != posY2) {// x1,y1 to x2,y1 to x2,y2if (containsAllOrNoneZeroInRow(posX1, posY1, posX2, posY1)&& map[posX2][posY1] == 0&& containsAllOrNoneZeroInColumn(posX2, posY1, posX2,posY2)) {return true;}// x1,y1 to x1,y2 to x2,y2if (containsAllOrNoneZeroInColumn(posX1, posY1, posX1, posY2)&& map[posX1][posY2] == 0&& containsAllOrNoneZeroInRow(posX1, posY2, posX2,posY2)) {return true;}}return false;}// 是否可以三直线相连private boolean isLinkByThreeLines(int posX1, int posY1, int posX2,int posY2) {if (isOnSameEdge(posX1, posY1, posX2, posY2)) {return true;}if (isOnThreeLinesLikeArc(posX1, posY1, posX2, posY2)) {return true;}if (isOnThreeLinesLikeZigzag(posX1, posY1, posX2, posY2)) {return true;}return false;}// 是否可以三直线相连,似U形private boolean isOnThreeLinesLikeArc(int posX1, int posY1, int posX2,int posY2) {if (isOnUpArc(posX1, posY1, posX2, posY2)) {return true;}if (isOnDownArc(posX1, posY1, posX2, posY2)) {return true;}if (isOnLeftArc(posX1, posY1, posX2, posY2)) {return true;}if (isOnRightArc(posX1, posY1, posX2, posY2)) {return true;}return false;}private boolean isOnUpArc(int posX1, int posY1, int posX2, int posY2) {// Y --> 0int lessY = posY1 < posY2 ? posY1 : posY2; //找小yfor (int j = lessY - 1; j >= 0; j--) {if (containsAllOrNoneZeroInRow(posX1, j, posX2, j)&& containsAllOrNoneZeroInColumn(posX1, posY1, posX1, j)&& containsAllOrNoneZeroInColumn(posX2, posY2, posX2, j)&& map[posX1][j] == 0 && map[posX2][j] == 0) {return true;}}if (isOnSameEdge(posX1, 0, posX2, 0)&& containsAllOrNoneZeroInColumn(posX1, posY1, posX1, 0)&& containsAllOrNoneZeroInColumn(posX2, posY2, posX2, 0)&& (map[posX1][0] == 0 && map[posX2][0] == 0|| map[posX1][0] == 0&& map[posX2][0] == map[posX2][posY2] || map[posX1][0] == map[posX1][posY1]&& map[posX2][0] == 0)) {return true;}return false;}private boolean isOnDownArc(int posX1, int posY1, int posX2, int posY2) {int moreY = posY1 < posY2 ? posY2 : posY1;for (int j = moreY + 1; j <= 8 - 1; j++) {if (containsAllOrNoneZeroInRow(posX1, j, posX2, j)&& containsAllOrNoneZeroInColumn(posX1, posY1, posX1, j)&& containsAllOrNoneZeroInColumn(posX2, posY2, posX2, j)&& map[posX1][j] == 0 && map[posX2][j] == 0) {return true;}}if (isOnSameEdge(posX1, 8 - 1, posX2, 8 - 1)&& containsAllOrNoneZeroInColumn(posX1, posY1, posX1, 8 - 1)&& containsAllOrNoneZeroInColumn(posX2, posY2, posX2, 8 - 1)&& (map[posX1][8 - 1] == 0 && map[posX2][8 - 1] == 0|| map[posX1][8 - 1] == map[posX1][posY1]&& map[posX2][8 - 1] == 0 || map[posX1][8 - 1] == 0&& map[posX2][8 - 1] == map[posX2][posY2])) {return true;}return false;}// ﹚private boolean isOnLeftArc(int posX1, int posY1, int posX2, int posY2) {int lessX = posX1 < posX2 ? posX1 : posX2;for (int i = lessX - 1; i >= 0; i--) {if (containsAllOrNoneZeroInColumn(i, posY1, i, posY2)&& containsAllOrNoneZeroInRow(i, posY1, posX1, posY1)&& containsAllOrNoneZeroInRow(i, posY2, posX2, posY2)&& map[i][posY1] == 0 && map[i][posY2] == 0) {return true;}}if (isOnSameEdge(0, posY1, 0, posY2)&& containsAllOrNoneZeroInRow(0, posY1, posX1, posY1)&& containsAllOrNoneZeroInRow(0, posY2, posX2, posY2)&& (map[0][posY1] == 0 && map[0][posY2] == 0|| map[0][posY1] == map[posX1][posY1]&& map[0][posY2] == 0 || map[0][posY1] == 0&& map[0][posY2] == map[posX2][posY2])) {return true;}return false;}// (private boolean isOnRightArc(int posX1, int posY1, int posX2, int posY2) {int moreX = posX1 < posX2 ? posX2 : posX1;for (int i = moreX + 1; i <= 8 - 1; i++) {if (containsAllOrNoneZeroInColumn(i, posY1, i, posY2)&& containsAllOrNoneZeroInRow(i, posY1, posX1, posY1)&& containsAllOrNoneZeroInRow(i, posY2, posX2, posY2)&& map[i][posY1] == 0 && map[i][posY2] == 0) {return true;}}if (isOnSameEdge(8 - 1, posY1, 8 - 1, posY2)&& containsAllOrNoneZeroInRow(posX1, posY1, 8 - 1, posY1)&& containsAllOrNoneZeroInRow(posX2, posY2, 8 - 1, posY2)&& (map[8 - 1][posY1] == 0 && map[8 - 1][posY2] == 0|| map[8 - 1][posY1] == map[posX1][posY1]&& map[8 - 1][posY2] == 0 || map[8 - 1][posY1] == 0&& map[8 - 1][posY2] == map[posX2][posY2])) {return true;}return false;}// 是否可以三直线相连,似之字形Nprivate boolean isOnThreeLinesLikeZigzag(int posX1, int posY1,int posX2, int posY2) {if (isOnZigzagWith1Row2Cols(posX1, posY1, posX2, posY2)) {return true;}if (isOnZigzagWith2Rows1Col(posX1, posY1, posX2, posY2)) {return true;}return false;}// 是否可以三直线相连,似之字形, 两行一列 Zprivate boolean isOnZigzagWith2Rows1Col(int posX1, int posY1,int posX2, int posY2) {int moreX = posX1 < posX2 ? posX2 : posX1;int lessX = posX1 < posX2 ? posX1 : posX2;for (int i = lessX + 1; i < moreX; i++) {if (containsAllOrNoneZeroInColumn(i, posY1, i, posY2)&& containsAllOrNoneZeroInRow(i, posY1, posX1, posY1)&& containsAllOrNoneZeroInRow(i, posY2, posX2, posY2)&& map[i][posY1] == 0 && map[i][posY2] == 0) {return true;}}return false;}// 是否可以三直线相连,似之字形, 一行两列private boolean isOnZigzagWith1Row2Cols(int posX1, int posY1,int posX2, int posY2) {int moreY = posY1 < posY2 ? posY2 : posY1;int lessY = posY1 < posY2 ? posY1 : posY2;for (int j = lessY + 1; j < moreY; j++) {if (containsAllOrNoneZeroInRow(posX1, j, posX2, j)&& containsAllOrNoneZeroInColumn(posX1, posY1, posX1, j)&& containsAllOrNoneZeroInColumn(posX2, posY2, posX2, j)&& map[posX1][j] == 0 && map[posX2][j] == 0) {return true;}}return false;}// 是否处于游戏区域的4条边的同一边上private boolean isOnSameEdge(int posX1, int posY1, int posX2, int posY2) {if ((posY1 == posY2 && posY2 == 0)|| (posY1 == posY2 && posY2 == 8 - 1)|| (posX1 == posX2 && posX2 == 0)|| (posX1 == posX2 && posX2 == 8 - 1)) {return true;}return false;}public boolean ifcanTouch(int posX1, int posY1, int posX2, int posY2) {if (isLinkByOneLine(posX1, posY1, posX2, posY2)) {return true;}// 是否可以两直线相连if (isLinkByTwoLines(posX1, posY1, posX2, posY2)) {return true;}// 是否可以三直线相连if (isLinkByThreeLines(posX1, posY1, posX2, posY2)) {return true;}return false;}public void clearBlock() {if (clicktimes >=2) {if (map[coordinatey1][coordinatex1] == map[coordinatey][coordinatex]&& !((coordinatex1 == coordinatex) && (coordinatey1 == coordinatey))) {if (ifcanTouch(coordinatey1, coordinatex1, coordinatey,coordinatex)) {				if (map[coordinatey1][coordinatex1] > 0)score = score + 10;		map[coordinatey1][coordinatex1] = 0;map[coordinatey][coordinatex] = 0;guoguan();}}}}}public static void main(String[] args) {	String lookAndFeel ="javax.swing.plaf.metal.MetalLookAndFeel";//swing 外观和感觉try {UIManager.setLookAndFeel(lookAndFeel);} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (InstantiationException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (UnsupportedLookAndFeelException e) {// TODO Auto-generated catch blocke.printStackTrace();}Llk_2 frame = new Llk_2();frame.setTitle("连连看");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setBounds(100, 100, 560, 430);frame.setLocation(440, 100);frame.setSize(540, 440);frame.setVisible(true);}
}

2.运行演示

连连看小游戏


http://chatgpt.dhexx.cn/article/NZ3UTA0h.shtml

相关文章

南阳ACM 题目811:变态最大值 Java版

变态最大值 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB 难度&#xff1a;1 描述 Yougth讲课的时候考察了一下求三个数最大值这个问题&#xff0c;没想到大家掌握的这么烂&#xff0c;幸好在他的帮助下大家算是解决了这个问题&#xff0c;但是问题又来了。…

线程池的好处

线程池的好处: 一.降低资源消耗。通过重复利用已创建的线程降低线程创建和销毁造成的消耗。&#xff08;当线程run方法使用完毕后&#xff0c;下一个线程不用再次创建&#xff0c;直接利用上一个线程&#xff09; 二.提高响应速度。当任务到达时&#xff0c;任务可以不需要等到…

详解线程池的作用及Java中如何使用线程池

服务端应用程序&#xff08;如数据库和 Web 服务器&#xff09;需要处理来自客户端的高并发、耗时较短的请求任务&#xff0c;所以频繁的创建处理这些请求的所需要的线程就是一个非常消耗资源的操作。常规的方法是针对一个新的请求创建一个新线程&#xff0c;虽然这种方法似乎易…

线程池作用及Executors方法讲解

线程池的作用: 线程池作用就是限制系统中执行线程的数量。 根据系统的环境情况&#xff0c;可以自动或手动设置线程数量&#xff0c;达到运行的最佳效果&#xff1b;少了浪费了系统资源&#xff0c;多了造成系统拥挤效率不高。用线程池控制线程数量&#xff0c;其他线程排…

Qt工作笔记-线程池作用之一:限制系统中执行线程的数量

一、线程池的作用&#xff1a; 线程池作用就是限制系统中执行线程的数量。 根据系统的环境情况&#xff0c;可以自动或手动设置线程数量&#xff0c;达到运行的最佳效果&#xff1b;少了浪费了系统资源&#xff0c;多了造成系统拥挤效率不高。用线程池控制线程数量&#xff0c;…

Android:Android线程和线程池的作用

文章目录 前言一、线程池概念好处线程池的创建参数含义工作机制RejectedExecutionHandler&#xff08;饱和策略&#xff09; 二、Android线程形态1.AsyncTask特点作用缺点生命周期注意事项 具体使用源码分析小结 2.HandlerThread特点作用具体使用 3.IntentService源码分析 总结…

线程池作用和参数原理

线程池的作用 减少资源的开销 减少了每次创建线程、销毁线程的开销。 提高响应速度每次请求到来时&#xff0c;由于线程的创建已经完成&#xff0c;故可以直接执行任务&#xff0c;因此提高了响应速度。提高线程的可管理性 线程是一种稀缺资源&#xff0c;若不加以限制&#x…

线程池作用、用法以及原理

线程池 作用用法建议设定大小快捷构造线程池submit与executeshutdown与shutdownNowFuture与FutureTast代码 状态底层原理继承关系主要参数工作原理饱和策略连接复用 作用 1&#xff0c;降低资源消耗。通过重复利用已创建的线程降低线程创建和销毁造成的消耗 2&#xff0c;提高…

线程池-线程池的好处

1.线程池的好处。 线程使应用能够更加充分合理的协调利用cpu 、内存、网络、i/o等系统资源。 线程的创建需要开辟虚拟机栈&#xff0c;本地方法栈、程序计数器等线程私有的内存空间。 在线程的销毁时需要回收这些系统资源。频繁的创建和销毁线程会浪费大量的系统资源&#xff0…

什么是线程池,线程池的作用

线程池&#xff0c;--其实就是一个 容纳多个线程的容器 &#xff0c;其中的线程可以反复使用&#xff0c;省去了频繁创建线程对象的操作 &#xff0c;--无需反复创建线程而消耗过多资源。 创建销毁线程是一个非常消耗性能的。 我们详细的解释一下为什么要使用线程池&#xff1f…

华为防火墙实战配置教程,太全了

防火墙是位于内部网和外部网之间的屏障&#xff0c;它按照系统管理员预先定义好的规则来控制数据包的进出。防火墙是系统的第一道防线&#xff0c;其作用是防止非法用户的进入。 本期我们一起来总结下防火墙的配置&#xff0c;非常全面&#xff0c;以华为为例。 防火墙的配置…

防火墙配置(命令)

拓扑图&#xff1a; 目的&#xff1a;PC1和PC2相互ping通。 配置命令&#xff1a; FW1: //添加端口IP [SRG-GigabitEthernet0/0/0]interface GigabitEthernet0/0/1 [SRG-GigabitEthernet0/0/1]ip add 192.168.1.1 24 [SRG]inter g0/0/2 [SRG-GigabitEthernet0/0/2]ip add 10.…

防火墙基础配置(二)

拓补图&#xff1a; 方案一&#xff08;子接口的形式&#xff09; 实验目的&#xff1a;解决防火墙上的接口不足以为其他区域服务的问题&#xff0c;比方说防火墙上只有两个接口&#xff0c;但是有三个区域&#xff0c;那这个实验的目的为了解决防火墙上的接口不足以为多区域提…

H3C防火墙基础配置2-配置安全策略

1 安全策略简介 安全策略对报文的控制是通过安全策略规则实现的&#xff0c;规则中可以设置匹配报文的过滤条件&#xff0c;处理报文的动作和对于报文内容进行深度检测等功能。 &#xff08;1&#xff09;规则的名称和编号 安全策略中的每条规则都由唯一的名称和编号标识。名称…

H3C防火墙-安全域配置举例

1. 组网需求 某公司以 Device 作为网络边界安全防护设备&#xff0c;连接公司内部网络和 Internet。公司只对内部提供Web 服务&#xff0c;不对外提供这些服务。现需要在设备上部署安全域&#xff0c;并基于以下安全需求进行域间策略 的配置。 • 与接口 GigabitEthernet1/0/1 …

Firewalld防火墙实例配置

文章目录 环境拓扑需求描述一、环境配置二、防火墙配置1、在网站服务器上配置防火墙2、网关服务器配置防火墙3、企业内网访问外网web服务器4、外网web服务器访问企业内部网站服务器 三、总结问题总结解决方案 环境拓扑 需求描述 1、 网关服务器连接互联网网卡ens33地址为100.1…

【Linux】配置网络和firewall防火墙(超详细介绍+实战)

&#x1f947;&#x1f947;【Liunx学习记录篇】&#x1f947;&#x1f947; 篇一&#xff1a;【Linux】VMware安装unbuntu18.04虚拟机-超详细步骤(附镜像文件&#xff09; 篇二&#xff1a;【Linux】ubuntu18.04系统基础配置及操作 篇三&#xff1a;【Linux】用户与组的操作详…

防火墙配置

防火墙&#xff08;Firewall&#xff09;&#xff0c;也称防护墙。它是一种位于内部网络与外部网络之间的网络安全系统。一项信息安全的防护系统&#xff0c;依照特定的规则&#xff0c;允许或是限制传输的数据通过。防火墙对于我们的网络安全的重要性不言而喻 但是在实际的开发…

H3C防火墙-安全策略典型配置举例

基于 IP 地址的安全策略配置举例 1.组网需求 • 某公司内的各部门之间通过 Device 实现互连&#xff0c;该公司的工作时间为每周工作日的 8 点到 18点。 • 通过配置安全策略规则&#xff0c;允许总裁办在任意时间、财务部在工作时间通过 HTTP 协议访问财务数据库服务器的 Web…

华为防火墙配置教程

01 了解防火墙基本机制 配置防火墙之前请了解防火墙基本工作机制。 1.1 什么是防火墙 防火墙是一种网络安全设备&#xff0c;通常位于网络边界&#xff0c;用于隔离不同安全级别的网络&#xff0c;保护一个网络免受来自另一个网络的攻击和入侵。这种“隔离”不是一刀切&#x…