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 LianLianKan extends JFrame {
private static final long serialVersionUID = 1L;
public LianLianKan() {
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; // 种类,随机x
private int coordinatex, coordinatey, coordinatex1, coordinatey1; // 坐标X
private 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("src/im/bk.jpg");
ImageIcon aIcon = new ImageIcon("src/im/1.gif");
ImageIcon bIcon = new ImageIcon("src/im/2.gif");
ImageIcon cIcon = new ImageIcon("src/im/3.gif");
ImageIcon dIcon = new ImageIcon("src/im/4.gif");
ImageIcon eIcon = new ImageIcon("src/im/5.gif");
ImageIcon fIcon = new ImageIcon("src/im/6.gif");
ImageIcon gIcon = new ImageIcon("src/im/7.gif");
ImageIcon hIcon = new ImageIcon("src/im/8.gif");
ImageIcon iIcon = new ImageIcon("src/im/9.gif");
ImageIcon jIcon = new ImageIcon("src/im/10.gif");
ImageIcon kIcon = new ImageIcon("src/im/11.gif");
ImageIcon lIcon = new ImageIcon("src/im/12.gif");
ImageIcon mIcon = new ImageIcon("src/im/13.gif");
ImageIcon nIcon = new ImageIcon("src/im/14.gif");
ImageIcon oIcon = new ImageIcon("src/im/15.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++)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本系统结构如下: (1)消除模块: 完成连连看游戏消除动作的模块。 (2)重新开始模块: 完成连连看游戏中重新开始新一局游戏功能的模块。 (3)刷新模块: 完成连连看游戏中,将游戏中未消除的图片个数记录并重新随机放置等数量图片的功能模块。 (4)选择难度模块: 完成游戏中切换游戏难度并开始新一局游戏的模块。 (5)计时模块: 完成游戏中倒计时并显示提示信息的模块。 (6)状态显示模块: 完成游戏中对游戏得分、闯关数记录的模块。 详情页面: https://blog.csdn.net/jonny903/article/details/130042631
资源推荐
资源详情
资源评论
收起资源包目录
使用Java Swing开发连连看小游戏.rar (45个子文件)
使用Java Swing开发连连看小游戏
.classpath 299B
.settings
org.eclipse.jdt.core.prefs 598B
src
.classpath 301B
.settings
org.eclipse.jdt.core.prefs 598B
im
bk.jpg 5KB
12.gif 2KB
6.gif 2KB
8.gif 2KB
14.gif 2KB
7.gif 2KB
5.gif 2KB
2.gif 2KB
9.gif 2KB
15.gif 2KB
3.gif 2KB
11.gif 2KB
1.gif 2KB
13.gif 2KB
4.gif 2KB
10.gif 2KB
LianLianKan.java 22KB
.project 380B
bin
.classpath 301B
LianLianKan$LianLianKanJPanel$loudou.class 3KB
.settings
org.eclipse.jdt.core.prefs 598B
LianLianKan$LianLianKanJPanel.class 13KB
im
bk.jpg 5KB
12.gif 2KB
6.gif 2KB
8.gif 2KB
14.gif 2KB
7.gif 2KB
5.gif 2KB
2.gif 2KB
9.gif 2KB
15.gif 2KB
3.gif 2KB
11.gif 2KB
1.gif 2KB
13.gif 2KB
4.gif 2KB
10.gif 2KB
LianLianKan.class 2KB
.project 380B
.project 387B
共 45 条
- 1
资源评论
强尼903
- 粉丝: 2
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 数据库课程设计-基于的个性化购物平台的建表语句.sql
- 数据库课程设计-基于的图书智能一体化管理系统的建表语句.sql
- Java 代码覆盖率库.zip
- Java 代码和算法的存储库 也为该存储库加注星标 .zip
- 免安装Windows10/Windows11系统截图工具,无需安装第三方截图工具 双击直接使用截图即可 是一款免费可靠的截图小工具哦~
- Libero Soc v11.9的安装以及证书的获取(2021新版).zip
- BouncyCastle.Cryptography.dll
- 5.1 孤立奇点(JD).ppt
- 基于51单片机的智能交通灯控制系统的设计与实现源码+报告(高分项目)
- 什么是 SQL 注入.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功