基于JAVA的连连看游戏设计与实现
- 格式:pdf
- 大小:1.06 MB
- 文档页数:27
基于JAVA的《连连看》游戏一引言《连连看》游戏在网上种类非常多,比如《水果连连看》,《宠物连连看》等等,虽然版本各种各样,但是其基本玩法,或者说基本算法是相同的,就是显示一些图标,让用户依次去点击两个图标,如果这两个图标相同,并且这两个图标通过直线可以相连,或者通过直角相连,或者通过双折线相连就可以消掉,消掉所有图标即为胜利。
如图1所示:图1 正在进行中的连连看游戏通过该游戏的制作,我们可以对Java的基础语法、Java图形界面以与简单的算法设计有一个比较全面的了解。
二设计要求为了避免叙述的繁琐,我们只实现连连看游戏的基本功能,如下:●制作如图1所示的游戏界面,尽量做到美观大方,使用方便●当两个图标相同,且通过直线相连、直角相连、双折线相连时,能够消掉图标●能够让游戏随时暂停,然后继续●当游戏进行到一定程度,无法消除剩余图标时,要能够提供重排功能对图标进行重排,从而让游戏继续进行三实现思路我们先讲一下程序中的几个难点,主要是说清楚具体的实现思路,具体的代码会在文后给出,大家可以参考。
1、界面设计需要实现如图2所示的界面:图 2 连连游戏界面整个界面分为三个区域:菜单区、功能区、游戏区。
首先在窗体上放置三个面板JPanel,分别存放三个区域,如图3所示:图3 界面的设计系统菜单区放置菜单即可,用户游戏区放置一个8*9的按钮数组来构成游戏界面,用户交互区放置开始,暂停等功能按钮以与提示信息。
2、生成游戏区运行程序后,游戏区并不显示按钮数组,当点击开始按钮后,再自动生成。
在生成按钮时要求按钮上的图案是随机的,且每个图案必须是偶数,否则会出现无法消除的按钮。
如何实现呢?我们可以这样考虑:假设有12个图片,把图片名字按照数字序号从0到11命名;假设游戏区共72个按钮,那么产生36个12以内的随机数字(每个随机数字代表一个图片),放入一个ArrayList中,最后使用ArrayList的addAll方法对已经产生的36个随机数字复制一份,这样就获得了72个随机数字,并且是成对的。
基于java的连连看游戏设计与实现的研究报告随着信息化时代的发展和互联网的普及,网络游戏成为现代生活的重要组成部分之一,连连看游戏作为其中的佼佼者一直深受玩家们的喜爱。
本次研究以Java语言为基础,设计并实现了一款基于图形用户界面的连连看游戏,从游戏设计、编程实现以及测试三个方面进行详细介绍。
一、游戏设计该连连看游戏设计的基础是二维数组。
玩家通过鼠标点击选择两个同样的图片,连接它们的线路不能经过其他图标,且路径短优先。
游戏共18个关卡,每个关卡的难度依次递增,并拥有不同主题的图片素材。
二、编程实现该游戏使用Java Swing绘制图形用户界面,整个游戏主要包括五个类:Main、Game、Node、Action、Panel。
1.Main类:主要作用为程序入口。
通过创建Game对象启动游戏。
2.Game类:游戏类。
在该类中主要完成游戏的初始化、监听器、关卡切换、连通性判断等操作。
3.Node类:节点类。
主要用于表示每一个图标,包括坐标以及图标种类等信息。
4.Action类:动作类。
主要用于计算玩家所选的两点是否可以连通。
5.Panel类:面板类。
界面主要交由Panel完成。
在该类中完成了界面布局、游戏信息展示等工作。
三、测试在游戏的测试过程中,主要测试了游戏的各个关卡能否正常切换和连通性判断能否正常运行。
此外,还通过在不同操作系统和不同分辨率下的测试,保证了游戏适用性和兼容性。
四、总结本次研究成功地设计并实现了一款基于Java的连连看游戏。
通过该游戏的设计与实现过程,进一步深入了解了Java编程语言以及Swing界面库的应用与优势。
最终测试结果表明,该游戏在各种操作系统和分辨率下均表现出良好的兼容性和适用性,可供广大玩家使用。
但仍有一些不足之处,需要进一步完善和优化。
在本次基于Java的连连看游戏设计与实现研究中,我们对玩家游戏数据进行了收集与分析。
具体数据如下:1. 游戏总胜利次数:1022. 最高得分:97633. 游戏失败次数:464. 游戏累计时间:20小时15分通过对这些游戏数据的分析,我们可以得出以下结论:1. 游戏整体受欢迎度较高,玩家胜利次数较多。
连连看游戏java课程设计一、课程目标知识目标:1. 理解Java语言中面向对象编程的基本概念,如类、对象、继承、封装等;2. 学会使用Java编写连连看游戏的界面布局和逻辑控制;3. 掌握运用Java集合框架处理游戏数据结构;4. 了解Java事件处理机制,并能应用于游戏交互。
技能目标:1. 能够运用面向对象的方法设计游戏类和对象,实现游戏功能;2. 独立编写连连看游戏的界面和逻辑代码,完成一个完整的Java游戏项目;3. 学会使用集合框架优化游戏数据存储和访问;4. 提高问题分析、程序设计和调试能力。
情感态度价值观目标:1. 培养学生对编程的兴趣,激发创造力和创新能力;2. 培养学生合作学习、分享交流的良好习惯,提高团队协作能力;3. 强化学生的逻辑思维能力,提高解决实际问题的能力;4. 培养学生面对挑战时的积极态度,勇于克服困难,持续优化和完善自己的作品。
课程性质:本课程为信息技术学科选修课程,以项目为导向,注重实践操作和团队合作。
学生特点:学生具备一定的Java编程基础,对游戏开发有浓厚兴趣,具有较强的动手能力和创新能力。
教学要求:结合实际项目需求,引导学生运用所学知识解决问题,注重培养学生的编程能力和团队协作能力,提高学生的综合素质。
通过本课程的学习,使学生能够独立完成一个连连看游戏的Java课程设计。
二、教学内容1. 面向对象编程基础复习:复习Java中类与对象、继承、封装等基本概念,参考教材第二章。
2. 游戏界面设计:学习使用Java的Swing库设计连连看游戏界面,包括菜单、按钮、网格布局等,结合教材第四章。
- 界面组件及布局管理器;- 事件监听器和处理机制;- 图形和图标的使用。
3. 游戏逻辑实现:学习实现游戏核心逻辑,如数据结构设计、游戏规则、配对消除等,参考教材第六章。
- 集合框架的使用;- 算法实现(如查找、排序);- 游戏流程控制。
4. 游戏对象设计:设计游戏中的对象类,如卡片类、游戏引擎类等,运用封装、继承等面向对象原则,参考教材第三章。
基于Java的图片连连看游戏设计研究基于Java的图片连连看游戏设计研究摘要:连连看(Link Up)游戏是一款经典的益智游戏,通过消除相同的图案来获得分数。
本文基于Java编程语言,对连连看游戏的设计进行深入研究。
通过实现游戏的基本功能和特色功能,对游戏进行优化和改进,提升游戏的用户体验。
通过实践验证,本设计具有一定的可行性和实用性。
1. 引言连连看游戏是一种非常受欢迎的益智游戏,其规则简单,操作容易上手。
随着移动互联网的快速发展,游戏市场越来越庞大。
设计一款基于Java的图片连连看游戏,可以满足用户对游戏的需求,同时也是提升自己编程能力的学习机会。
2. 游戏的基本功能设计2.1 游戏界面设计游戏主界面分为游戏区和得分区。
游戏区由多个方格组成,每个方格里面有一张图案,玩家需要通过点击两个相同的图案来消除它们。
得分区显示玩家的得分、剩余时间和游戏关卡等信息。
2.2 游戏规则设计游戏开始时,系统会随机生成一定数量的图案并填充到游戏区中。
玩家需要通过连接相同的图案来消除它们,直到清空游戏区中所有的图案。
连接两个图案的连线只能是水平或垂直直线,并且在连线路径上不能有其他图案阻挡。
玩家每消除一对图案,得分增加,游戏关卡随之升级。
如果无法连接两个图案,玩家可以使用提示功能获取一定的帮助。
3. 游戏特色功能设计3.1 计时功能游戏设置了一个倒计时器,玩家需要在规定的时间内完成游戏。
当倒计时为0时,游戏结束,系统会显示玩家的得分和游戏结束画面。
3.2 关卡功能游戏设计了多个关卡,每个关卡的游戏难度和图案数量都不同。
玩家需要通过完成前一关卡的要求才能解锁下一关卡。
3.3 提示功能当玩家遇到无法连接的图案时,可以使用提示功能,系统会自动给出可以连接的图案,并帮助玩家找到解决方案。
4. 游戏的优化与改进4.1 性能优化在游戏的设计过程中,需要考虑到游戏的性能问题。
通过合理的算法设计和资源管理,减少游戏的内存占用和运行时的开销,提高游戏的运行速度和流畅度。
滨江学院实验报告||实验名称JAVA小游戏(连连看)设计课程名称智能手机程序设计| |专业班级:信息工程1班学生姓名:车宇翔学号:20112309002指导教师:高超学期:2013-2014(2)成绩:【选题背景】:连连看游戏经验,玩法简单,休闲,益智,趣味,广受欢迎。
【选题目的】:学会JAVA程序开发的环境搭建与配置,并在实际运用中学习和掌握JAVA程序开发的全过程。
进一步熟悉掌握JAVA程序设计语音的基础内容,如用户图形界面设计、JAVA多线程编程、JAVA数据库编程等。
通过亲自动手写程序,拓展知识面,锻炼调试能力。
【系统分析与设计】:功能分析:实现连连看的基本游戏功能和重置、提示、消除功能设计:通过对图片的调用以及设置是否可见来完成连连看的效果【课程设计中碰到的问题及解决方案】:1.不知道如何进行对数组中两个元素是否可以消除的判断2.时间条的动态表现解决方案:1.对每个相同图案进行循环判断,直到找出满足条件的情况boolean verticalMatch(Point a, Point b) // 竖线上的判断boolean horizonMatch(Point a, Point b) // 横线上的判断2.为了保证动画过程和游戏过程的平行运行,因此将动画分离成一个独立的控件,并且要保证动画有自己单独的线程来运行。
当每次用户的分数发生变化时,我们可以使用setScore(int l, int c) 方法同步分数显示的动画效果。
【程序输出结果】:游戏开始【程序代码】:ImageFactorypackage nicholas.game.kyodai;import javax.swing.ImageIcon;import .*;public class ImageFactory {private static ImageFactory imagefactory;private static ImageIcon images[];private ImageFactory() {images = new ImageIcon[54];URLClassLoader loader = (URLClassLoader)getClass().getClassLoader();for(int i=0;i<39;i++) {images[i] = new ImageIcon(getClass().getResource("images/"+i+".gif"));}images[39] = new ImageIcon(getClass().getResource("images/dots.gif"));images[40] = new ImageIcon(getClass().getResource("images/ico.gif"));images[41] = new ImageIcon(getClass().getResource("images/topbar.gif"));images[42] = new ImageIcon(getClass().getResource("images/splash.gif"));images[43] = new ImageIcon(getClass().getResource("images/sico.gif"));}public ImageIcon getImageicon(int i) {return images[i];}public static synchronized ImageFactory getInstance() {if(imagefactory != null) {return imagefactory;} else {imagefactory = new ImageFactory();return imagefactory;}}}KyodaiGridpackage nicholas.game.kyodai;import java.awt.*;import javax.swing.*;public class KyodaiGrid extends JLabel {private int xpos;private int ypos;public KyodaiGrid(int x, int y) {xpos = x;ypos = y;this.setHorizontalAlignment(SwingConstants.CENTER);}public int getXpos() {return xpos;}public int getYpos() {return ypos;}public boolean isPassable() {return !isVisible();}}LevelInfopackage nicholas.game.kyodai;import java.io.Serializable;public class LevelInfo implements Serializable {//xBound为行号,yBound为列号private int xBound;private int yBound;public LevelInfo() {xBound = 16;yBound = 9;}public LevelInfo(int x, int y){xBound = x;yBound = y;}public int getXBound() {return xBound;}public int getYBound() {return yBound;}}MainFrame.javapackage nicholas.game.kyodai;import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;import nicholas.swing.AboutDialog;import nicholas.swing.JSplashWindow;public class MainFrame extends JFrame implements ActionListener {private JMenuItem aboutItem;//菜单栏private JMenuItem exitItem;private JMenuItem startItem;private JMenuItem optionItem;private JMenuItem tipItem;private JMenuItem refreshItem;private JMenuItem logItem;private JMenuItem bombItem;private JMenuItem pauseItem;private MainPanel mainPanel;//完成主要功能private LevelInfo levelInfo;public MainFrame() {super("连连看");levelInfo = new LevelInfo();//设定游戏大小setMenuBar();//设置菜单setUI();setIconImage(ImageFactory.getInstance().getImageicon(43).getImage());setSize(650,520);Dimension screen = getToolkit().getScreenSize();setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2);this.setVisible(true);addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});}private void setMenuBar() {JMenu fileMenu = new JMenu("游戏(G)");JMenu helpMenu = new JMenu("帮助(H)");JMenu contMenu = new JMenu("辅助(C)");fileMenu.setMnemonic('G');helpMenu.setMnemonic('H');contMenu.setMnemonic('C');startItem = new JMenuItem("开局(N)");startItem.setMnemonic('N');startItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2,0));pauseItem = new JMenuItem("暂停(P)");pauseItem.setMnemonic('P');pauseItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAUSE,0));refreshItem = new JMenuItem("刷新(R)");refreshItem.setMnemonic('R');refreshItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,0));tipItem = new JMenuItem("提示(T)");tipItem.setMnemonic('T');tipItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));optionItem = new JMenuItem("选项(O)...");optionItem.setMnemonic('O');logItem = new JMenuItem("排行榜(B)...");logItem.setMnemonic('B');exitItem = new JMenuItem("退出(X)");exitItem.setMnemonic('X');aboutItem = new JMenuItem("关于(A)...");aboutItem.setMnemonic('A');aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));bombItem = new JMenuItem("炸弹(M)");bombItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,0));bombItem.setMnemonic('M');startItem.addActionListener(this);pauseItem.addActionListener(this);refreshItem.addActionListener(this);tipItem.addActionListener(this);optionItem.addActionListener(this);logItem.addActionListener(this);exitItem.addActionListener(this);aboutItem.addActionListener(this);bombItem.addActionListener(this);fileMenu.add(startItem);fileMenu.add(pauseItem);contMenu.add(refreshItem);contMenu.add(bombItem);contMenu.add(tipItem);fileMenu.addSeparator();fileMenu.add(exitItem);helpMenu.add(aboutItem);helpMenu.add(contMenu);JMenuBar bar = new JMenuBar();bar.add(fileMenu);bar.add(helpMenu);setJMenuBar(bar);}private void setUI() {mainPanel = new MainPanel(levelInfo);getContentPane().add(mainPanel,BorderLayout.CENTER); }public static void main(String args[]) {MainFrame application = new MainFrame();}private void showAboutDialog() {String s1="作者:车宇翔";String s2="邮箱: 531608022@";String s3="Have Fun!!";TextArea ta=new TextArea();ta.setText(s1+"\n"+"\n"+"\n"+s2+"\n"+"\n"+"\n"+s3);ta.setEditable(false);JFrame f=new JFrame("关于");f.setLocation(300, 300);f.setSize(200,200);f.add(ta);f.setBackground(new Color(200,120,150));f.setResizable(false);f.setVisible(true);}public void actionPerformed(ActionEvent ae) { if(ae.getSource()==startItem) {mainPanel.restart();} else if(ae.getSource()==pauseItem) {mainPanel.setPaused(!mainPanel.isPaused());} else if(ae.getSource()==exitItem) {System.exit(0);} else if(ae.getSource()==aboutItem) {showAboutDialog();} else if(ae.getSource()==bombItem) {eBomb();} else if(ae.getSource()==refreshItem) {mainPanel.refresh();} else if(ae.getSource()==tipItem) {mainPanel.showNext();}}}MainPanel.javapackage nicholas.game.kyodai;import java.awt.*;import java.awt.event.*;import java.util.Vector;import javax.swing.*;import javax.swing.border.Border;import nicholas.game.kyodai.*;public class MainPanel extends JPanel {private int BOMB = 5;private int BOMBP = 200;private int REFRESH = 4;private int REFRP = 250;private int TIP = 7;private int TIPP = 120;private int PROGRESS = 1200;private int xBound;private int yBound;private int pcount;private int score;private int refreshcount;private int bombcount;private int tipcount;private LevelInfo levelInfo; private GridMouseAdapter gma; private KyodaiGrid grid[][]; private KyodaiGrid nexts, nexte;private Border selectedBorder; private Border opaqueBorder; private Border tipBorder;private Vector path[];private Thread pthread;private JProgressBar progress; private JLabel scoreLabel; private JLabel refreshLabel; private JLabel bombLabel;private JLabel tipLabel;private JPanel gridPanel;private boolean wingame;public MainPanel(LevelInfo li) {super(new BorderLayout());levelInfo = li;path = new Vector[3];path[0] = new Vector();path[1] = new Vector();path[2] = new Vector();setBackground(Color.black);gma = new GridMouseAdapter();opaqueBorder = BorderFactory.createLineBorder(getBackground());//selectedBorder = BorderFactory.createLineBorder(Color.red);selectedBorder = BorderFactory.createLineBorder(Color.red);tipBorder = BorderFactory.createLineBorder(Color.green);setGridPanel();setStatusPanel();}/***设置状态面板*/private void setStatusPanel() {wingame = false;JPanel panel = new JPanel();panel.setBackground(Color.black);JLabel label = new JLabel("剩余时间:");label.setForeground(Color.white);panel.add(label);progress = new JProgressBar(0,PROGRESS);//时间条显示progress.setValue(PROGRESS);progress.setPreferredSize(new Dimension(400,20));progress.setForeground(Color.blue);progress.setBorderPainted(false);panel.add(progress);score = 0;scoreLabel = new JLabel(""+score);scoreLabel.setForeground(Color.yellow);scoreLabel.setFont(new Font("Dialog",Font.BOLD,25));scoreLabel.setHorizontalAlignment(SwingConstants.RIGHT);scoreLabel.setPreferredSize(new Dimension(100,20));panel.add(scoreLabel);add(panel,BorderLayout.NORTH);panel = new JPanel();panel.setBackground(Color.black);label = new JLabel("剩余提示:");label.setForeground(Color.yellow);panel.add(label);tipcount = TIP;tipLabel = new JLabel(""+tipcount);tipLabel.setForeground(Color.green);panel.add(tipLabel);label = new JLabel("剩余炸弹:");label.setForeground(Color.yellow);panel.add(label);bombcount = BOMB;bombLabel = new JLabel(""+bombcount);bombLabel.setForeground(Color.green);panel.add(bombLabel);label = new JLabel("可用刷新:");label.setForeground(Color.yellow);panel.add(label);refreshcount = REFRESH;refreshLabel = new JLabel(""+refreshcount);refreshLabel.setForeground(Color.green);panel.add(refreshLabel);add(panel,BorderLayout.SOUTH);pthread = new ProgressThread();pthread.start();}private void setGridPanel() {//完成布局gridPanel = new JPanel();gridPanel.setBackground(getBackground());xBound = levelInfo.getXBound()+2;yBound = levelInfo.getYBound()+2;gridPanel.setLayout(new GridLayout(yBound,xBound,0,0));grid = new KyodaiGrid[yBound][xBound];int count = 0;int sub = levelInfo.getXBound()*levelInfo.getYBound()/4;KyodaiGrid temp[] = new KyodaiGrid[xBound*yBound];for(int y=0;y<yBound;y++) {for(int x=0;x<xBound;x++) {grid[y][x] = new KyodaiGrid(x, y);if(x==0||x==(xBound-1)||y==0||y==(yBound-1)) {grid[y][x].setIcon(ImageFactory.getInstance().getImageicon(39));grid[y][x].setVisible(false);} else {grid[y][x].setIcon(ImageFactory.getInstance().getImageicon(count%sub));grid[y][x].setBorder(opaqueBorder);grid[y][x].addMouseListener(gma);temp[count] = grid[y][x];count++;}gridPanel.add(grid[y][x]);}}JPanel t = new JPanel();t.setBackground(Color.black);t.add(gridPanel);add(t,BorderLayout.CENTER);shuffle(temp, count);}/***开始新游戏*/public void restart() {//重新开始resetStatusPanel();resetGridPanel();}/***重置面板状态和游戏图标*/private void resetStatusPanel() {wingame = false;score = 0;scoreLabel.setText(""+score);bombcount = BOMB;bombLabel.setText(""+bombcount);refreshcount = REFRESH;refreshLabel.setText(""+refreshcount);tipcount = TIP;tipLabel.setText(""+tipcount);progress.setValue(PROGRESS);pthread.resume();}private void resetGridPanel() {int count = 0;int sub = (xBound-2)*(yBound-2)/4;KyodaiGrid temp[] = new KyodaiGrid[xBound*yBound];for(int y=1;y<yBound-1;y++) {for(int x=1;x<xBound-1;x++){grid[y][x].setIcon(ImageFactory.getInstance().getImageicon(count%sub));grid[y][x].setBorder(opaqueBorder);grid[y][x].setVisible(true);temp[count] =grid[y][x];count++;}}shuffle(temp,count);}/***暂停*/public void setPaused(boolean p) {if(p) {pthread.suspend();gridPanel.setVisible(false);} else {pthread.resume();gridPanel.setVisible(true);}}/***是否暂停*/public boolean isPaused() {return !gridPanel.isVisible();}/***没有布局存在时胜利*计算得分*/private void win() {wingame = true;pthread.suspend();score += progress.getValue()/20+bombcount*BOMBP+refreshcount*REFRP+tipcount*TIPP;scoreLabel.setText(""+score);}private void shuffle(KyodaiGrid array[], int count) {if(wingame) return;do {setVisible(false);int j,k;Icon temp;for(int i=0;i<count;i++) {j = (int)(Math.random()*count);k = (int)(Math.random()*count);temp = array[k].getIcon();array[k].setIcon(array[j].getIcon());array[j].setIcon(temp);}setVisible(true);} while(!findPair());}public void refresh() {if(wingame||progress.getValue()==0||refreshcount==0) return;KyodaiGrid temp[] = new KyodaiGrid[xBound*yBound];int count = 0;for(int y=1;y<yBound-1;y++) {for(int x=1;x<xBound-1;x++) {if(grid[y][x].isVisible()) {grid[y][x].setBorder(opaqueBorder);temp[count] = grid[y][x];count++;}}}if(count!=0) {refreshcount--;refreshLabel.setText(""+refreshcount);shuffle(temp,count);} else win();}private boolean xdirect(KyodaiGrid start, KyodaiGrid end,Vector path) { if(start.getYpos()!=end.getYpos()) return false;int direct = 1;if(start.getXpos()>end.getXpos()) {direct = -1;}path.removeAllElements();for(intx=start.getXpos()+direct;x!=end.getXpos()&&x<xBound&&x>=0;x+=direct) { if(grid[start.getYpos()][x].isVisible()) return false;path.add(grid[start.getYpos()][x]);}path.add(end);return true;}private boolean ydirect(KyodaiGrid start, KyodaiGrid end,Vector path) { if(start.getXpos()!=end.getXpos()) return false;int direct = 1;if(start.getYpos()>end.getYpos()) {direct = -1;}path.removeAllElements();for(inty=start.getYpos()+direct;y!=end.getYpos()&&y<yBound&&y>=0;y+=direct) { if(grid[y][start.getXpos()].isVisible()) return false;path.add(grid[y][start.getXpos()]);}path.add(end);return true;}private int findPath(KyodaiGrid start, KyodaiGrid end) {//0 connerif(xdirect(start,end,path[0])) {return 1;}if(ydirect(start,end,path[0])) {return 1;}//1 connerKyodaiGrid xy = grid[start.getYpos()][end.getXpos()];if(!xy.isVisible()&&xdirect(start,xy,path[0])&&ydirect(xy,end,path[1])) {return 2;}KyodaiGrid yx = grid[end.getYpos()][start.getXpos()];if(!yx.isVisible()&&ydirect(start,yx,path[0])&&xdirect(yx,end,path[1])) {return 2;}//2 conner//uppath[0].removeAllElements();for(int y=start.getYpos()-1;y>=0;y--) {xy = grid[y][start.getXpos()];yx = grid[y][end.getXpos()];if(xy.isVisible()) break;path[0].add(xy);if(!yx.isVisible()&&xdirect(xy,yx,path[1])&&ydirect(yx,end,path[2])) {return 3;}}//downpath[0].removeAllElements();for(int y=start.getYpos()+1;y<yBound;y++) {xy = grid[y][start.getXpos()];yx = grid[y][end.getXpos()];if(xy.isVisible()) break;path[0].add(xy);if(!yx.isVisible()&&xdirect(xy,yx,path[1])&&ydirect(yx,end,path[2])) {return 3;}}//leftpath[0].removeAllElements();for(int x=start.getXpos()-1;x>=0;x--) {yx = grid[start.getYpos()][x];xy = grid[end.getYpos()][x];if(yx.isVisible()) break;path[0].add(yx);if(!xy.isVisible()&&ydirect(yx,xy,path[1])&&xdirect(xy,end,path[2])) {return 3;}}//rightpath[0].removeAllElements();for(int x=start.getXpos()+1;x<xBound;x++) {yx = grid[start.getYpos()][x];xy = grid[end.getYpos()][x];if(yx.isVisible()) break;path[0].add(yx);if(!xy.isVisible()&&ydirect(yx,xy,path[1])&&xdirect(xy,end,path[2])) {return 3;}}return 0;}/***在布局中消除配对*/private void deletePair(KyodaiGrid prev, KyodaiGrid current) {//尝试寻找路径//如果找到路径//animateVector temp = new Vector();temp.add(prev);for(int i=0;i<pcount;i++) {temp.addAll(path[i]);path[i].removeAllElements();}AnimateThread thread = new AnimateThread(temp);thread.start();score += progress.getValue()/20;scoreLabel.setText(""+score);progress.setValue(progress.getValue()+60);}/***展示找到的配对*/public void showNext() {if(wingame||progress.getValue()==0||tipcount==0) return;tipcount--;tipLabel.setText(""+tipcount);if(nexts!=null&&nexte!=null) {nexts.setBorder(tipBorder);nexte.setBorder(tipBorder);}}/***删除找到的配对*/public void useBomb() {if(wingame||progress.getValue()==0||bombcount==0) return;bombcount--;bombLabel.setText(""+bombcount);if(nexts!=null&&nexte!=null) {deletePair(nexts,nexte);}}/***发现有连接路径的配对*@返回是否发现*/private boolean findPair() {nexts = null;nexte = null;for(int sy=1;sy<yBound-1;sy++) {for(int sx=1;sx<xBound-1;sx++) {if(!grid[sy][sx].isVisible()) continue;for(int ey=sy;ey<yBound-1;ey++) {for(int ex=1;ex<xBound-1;ex++) {if(!grid[ey][ex].isVisible()||(ey==sy&&ex==sx)) continue;if(grid[sy][sx].getIcon()==grid[ey][ex].getIcon()) {pcount = findPath(grid[sy][sx],grid[ey][ex]);if(pcount!=0) {nexts = grid[sy][sx];nexte = grid[ey][ex];return true;}}}}}}return false;}private class GridMouseAdapter extends MouseAdapter { private KyodaiGrid prev;public void mouseClicked(MouseEvent me) {if(prev == null) {prev = (KyodaiGrid)me.getSource();prev.setBorder(selectedBorder);} else {if(progress.getValue()==0) return;KyodaiGrid current = (KyodaiGrid)me.getSource();if(current == prev) return;if(current.getIcon()==prev.getIcon()) {pcount = findPath(prev,current);if(pcount!=0) {deletePair(prev,current);//setprev = null;return;}}prev.setBorder(opaqueBorder);prev = current;prev.setBorder(selectedBorder);if(!findPair()) refresh();}}}private class AnimateThread extends Thread {private Vector v;public AnimateThread(Vector temp) {v = temp;}public void run() {KyodaiGrid prev = null;KyodaiGrid current;int j = 0;while(j<v.size()) {prev = (KyodaiGrid)v.remove(0);prev.setVisible(true);v.add(prev);j++;try {sleep(20);} catch(InterruptedException ire) {System.err.println("sleep interrupted");}}current = prev;prev = (KyodaiGrid)v.remove(0);while(!v.isEmpty()) {((KyodaiGrid)v.remove(0)).setVisible(false);try {sleep(20);} catch(InterruptedException ire) {System.err.println("sleep interrupted");}}prev.setVisible(false);current.setVisible(false);current.setIcon(ImageFactory.getInstance().getImageicon(39));prev.setIcon(ImageFactory.getInstance().getImageicon(39));current.setBorder(opaqueBorder);prev.setBorder(opaqueBorder);if(!findPair()) refresh();}//end of method run}private class ProgressThread extends Thread {public ProgressThread() {}public void run() {while(true) {while(progress.getValue()>0) {progress.setValue(progress.getValue()-1);try {sleep(100);} catch(InterruptedException ire) {System.err.println("sleep interrupted");}}repaint();suspend();}}}}【总结自己的体会和收获】:通过这次课程设计我学到了不少东西,也发现了大量的问题,同时在设计的过程中也发现了自己的不足之处,对以前学过的知识理解的不够深刻,对安卓手机小游戏的程序编写有了一定的了解。
基于Java的图片连连看游戏的设计与实现摘要:随着社会科技的不断进步,人们的娱乐消遣的方式也越来越来多,游戏成为了很多人的娱乐方式。
本文介绍了图片连连看的游戏规则,连连看游戏采用Eclipse开发平台,使用Java开发了一款单机水果卡通图片连连看的游戏。
关键词:Java;图片连连看;游戏设计[基金项目]安徽省质量工程项目(2021cyxy051;2021jyxm0912;2022jxgl040;2022xqhz044;2022sdxx020;2021jyxm0917);教育部产学合作协同育人项目(202002292027);蚌埠学院科学研究项目“淮河文化教育传播成效及大学生学习满意度研究”(2022SK02);蚌埠学院一流课程“线上线下混合式课程:现代教育技术”(2021xsxxhh14);安徽省大学生创新创业教育训练项目“基于Java的图片连连看游戏设计与实现”(202311305060)。
[作者简介]杨赛赛,男,蚌埠学院2021级软件工程专业学生,学号:52102041039;曹建磊(1988-),男,河南汝南人,硕士,讲师,主要研究方向为教育技术学;黄迎辉(1970-),男,安徽凤阳人,硕士,教授,主要研究方向自动化技术;朱洪浩(1980-),男,安徽砀山人,博士,副教授,主要研究方向机器学习;张新展,男,蚌埠学院2021级软件工程专业学生,学号:52102041043。
一、引言随着Java能将开发系统的可移植特性提高,Java在我们的社会生活中获得了广泛应用,Java开发的游戏也深受广大人群的喜爱和欢迎。
虽然Java开发的游戏在实际中的画面表现和场景效果等受到技术和设备的限制,但是构造简单,通用性,游戏响应比较快,其具备的优势受到普遍欢迎[1]。
连连看,是一种图案配对的益智游戏。
在电子游戏中,玩家可以将2个相同图案的对子连接起来,连接线不多于3根直线,就可以成功将对子消除。
该游戏具有不同的关卡难度,规则简单容易上手,游戏速度节奏快,操作简单容易上手,画面清晰可爱,是一款休闲娱乐游戏[2]。