ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:58.81KB ,
资源ID:6617816      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6617816.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(JAVA课程设计连连看最终版要点良心出品必属精品.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

JAVA课程设计连连看最终版要点良心出品必属精品.docx

1、JAVA课程设计连连看最终版要点良心出品必属精品JAVA课程设计报告实验题目: “连连看”游戏程序设计小组成员: 王飞铭、毛建平、陈银银、黄庭威 成员分工:组长:王飞铭王飞铭:actionPerformed():重来一局按钮的响应事件及remove()判断移去方法毛建平:xiao()消去方法、estimateEven()方法陈银银:init()方法:游戏主界面和main()方法实现黄庭威:randomBuild() 产生随机数方法、fraction()刷新方法(一):内容:1:功能需求和分析: (1) 该游戏界面为:数字方格类型,由6竖7横的直线平行垂直交叉而组成,分别是6行5列凹方块拼接,共

2、有30格小方块。方块上随机分布一些数字,数字的要求是至少两两相同,位置随机打乱。 (2) 游戏规则是:将相同数字的方块连接,但要满足只能至少单边无阻碍呈直线趋势连接,否则视为无效,如果一对数字连接成功,那么就会消失在界面,并且分数标签会加分,继续游戏,直到游戏结束。 (3)帮助项目:在游戏过程中,如果出现没有可以连接的数字对时候,可按界面下方按钮刷新重新排列,便可以可继续游戏。 (4)退出游戏: 可以鼠标点击 “退出”按钮,结束游戏。 (5) 再来一局:本局结束或者中途不想继续玩本局,可以点击界面下方的再来一局,系统会自动再次重新开始。(二):主要方法:首先我们定义了一个lianliankan

3、类,实现了接口ActionListener:1) init()方法:实现游戏主界面;2) randomBuild()方法:用来产生游戏按钮上的随机数;3) fraction()方法:游戏界面最上面用来加分;4) reload()方法:用来刷新,重载,窗体界面;5) estimateEven()方法:判断按钮数字是否满足消去的条件 linePassOne()方法:判断第一按钮同左右侧空按钮之间rowPassOne()方法:判断第一按钮同列空按钮与第二按钮;6) actionPerformed(ActionEvent e)方法:用来实现重来一局按钮的响应事件;7) main(String args

4、)方法:主函数;8) xiao()方法:消去方法(三):界面要求:用图形界面实现,参考下系统流程图如下(四):代码设计package 数字版;/*本游戏是连连看,上面出现的都是数字,点击两个相邻的或者之间没有第三个的,便可以消去。如果不能消除完,便可以按重列,这样会把剩余的重新排列。便可以继续玩了,或者您可以按重置,重新再来一局!*/import javax.swing.*; /调用图形界面类布局import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener /继承一个

5、监听器JFrame mainFrame; /游戏主面板 用布局管理器Container thisContainer; /一个容器JPanel centerPanel,southPanel,northPanel; /子面板 JButton diamondsButton = new JButton65;/游戏按钮数组 JButton exitButton,resetButton,newlyButton; /退出,重列,重新开始按钮 JLabel fractionLable=new JLabel(0); /分数标签 显示您玩游戏得了多少分!)JButton firstButton,secondBut

6、ton; /分别记录两次被选中的按钮 int grid = new int87;/储存游戏按钮位置 static boolean pressInformation=false; /判断是否有按钮被选中 int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; /游戏按钮的位置坐标 int i,j,k,n;/消除方法控制 public void init() mainFrame=new JFrame(数字版连连看); thisContainer = mainFrame.getContentPane(); thisContainer.setL

7、ayout(new BorderLayout();/setLayout()设置用户界面上的屏幕组件的格式布局,是java图形界面编程的常用方法。此处是方位布局centerPanel=new JPanel(); /中间部分(用来放游戏显示内容)southPanel=new JPanel(); /下面部分(用来放退出,重列,重新开始按钮)northPanel=new JPanel(); /上面部分(用来记录得分情况)centerPanel.setBackground(new Color(145,145,44);/灰色northPanel.setBackground(new Color(245,25

8、2,252);/颜色redthisContainer.add(centerPanel,Center); thisContainer.add(southPanel,South); thisContainer.add(northPanel,North); centerPanel.setLayout(new GridLayout(6,5); /设置游戏图标for(int cols = 0;cols 6;cols+) for(int rows = 0;rows 5;rows+ ) diamondsButtoncolsrows=new JButton(String.valueOf(gridcols+1r

9、ows+1); /换下一行diamondsButtoncolsrows.setBackground(new Color(199,190,33);/颜色diamondsButtoncolsrows.setFont(new java.awt.Font(黑体, 1, 22);diamondsButtoncolsrows.setBorder(BorderFactory.createLoweredBevelBorder();diamondsButtoncolsrows.addActionListener(this); centerPanel.add(diamondsButtoncolsrows); ex

10、itButton=new JButton(退出); exitButton.setFont(new java.awt.Font(黑体, 1, 16);exitButton.setPreferredSize(new Dimension(55,30);exitButton.setBorder(BorderFactory.createRaisedBevelBorder();exitButton.setBackground(new Color(25,155,100);/颜色绿色exitButton.addActionListener(this); resetButton=new JButton(刷新);

11、 resetButton.setFont(new java.awt.Font(黑体, 1, 16);resetButton.setPreferredSize(new Dimension(55,30);resetButton.setBorder(BorderFactory.createRaisedBevelBorder();resetButton.setBackground(new Color(77, 175,100);/蓝色resetButton.addActionListener(this); newlyButton=new JButton(再来一局); newlyButton.setFon

12、t(new java.awt.Font(黑体, 1, 16);newlyButton.setPreferredSize(new Dimension(100,33);newlyButton.setBorder(BorderFactory.createRaisedBevelBorder();newlyButton.setBackground(new Color(255,192,203);/粉色newlyButton.addActionListener(this); /添加了监听器 !当点击时候,用那个来通知southPanel.add(exitButton); southPanel.add(res

13、etButton); southPanel.add(newlyButton);fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText(); /用来计算得分数,不断变化northPanel.add(fractionLable); mainFrame.setBounds(300,100,500,450); mainFrame.setVisible(true); public void randomBuild() /产生随机数int randoms,cols,rows; for(int twins=1;t

14、wins=15;twins+) randoms=(int)(Math.random()*25+1); for(int alike=1;alike=2;alike+) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(gridcolsrows!=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); this.gridcolsrows=randoms; public void fraction() fractionLable.setTex

15、t(String.valueOf(Integer.parseInt(fractionLable.getText()+100); public void reload() int save = new int30; int n=0,cols,rows; int grid= new int87; /双重循环,输出二维数组!for(int i=0;i=6;i+) for(int j=0;j=0) cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(gridcolsrows!=0) cols=(int)(Math.ra

16、ndom()*6+1); rows=(int)(Math.random()*5+1); this.gridcolsrows=saven; n-; mainFrame.setVisible(false); pressInformation=false; /这里一定要将按钮点击信息归为初始 init(); for(int i = 0;i 6;i+) for(int j = 0;j 5;j+ ) if(gridi+1j+1=0) diamondsButtonij.setVisible(false); public void estimateEven(int placeX,int placeY,JBu

17、tton bz) if(pressInformation=false) x=placeX; y=placeY; secondMsg=gridxy; secondButton=bz; pressInformation=true; else x0=x; y0=y; fristMsg=secondMsg; firstButton=secondButton; x=placeX; y=placeY; secondMsg=gridxy; secondButton=bz; if(fristMsg=secondMsg & secondButton!=firstButton) xiao(); /调用消掉的方法

18、public void xiao() /相同的情况下能不能消去。仔细分析,不一条条注释 if(x0=x &(y0=y+1|y0=y-1) | (x0=x+1|x0=x-1)&(y0=y) /判断是否相邻 remove(); else for (j=0;jj) /如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边 for (i=y-1;i=j;i- ) /判断第二按钮左侧直到第一按钮中间有没有按钮 if (gridxi!=0) k=0; break; else k=1; /K=1说明通过了第一次验证 if (k=1) linePassOne(); if (yj) /如果第二个按钮

19、的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边 for (i=y+1;i=j ;i+ ) /判断第二按钮左侧直到第一按钮中间有没有按钮 if (gridxi!=0) k=0; break; else k=1; if (k=1) linePassOne(); if (y=j ) linePassOne(); if (k=2) if (x0=x) remove(); if (x0x) for (n=x0;nx) for (n=x0;n=x+1 ;n- ) if (gridnj!=0) k=0; break; if(gridnj=0 & n=x+1) remove(); for (i=0;ii

20、) for (j=x-1;j=i ;j- ) if (gridjy!=0) k=0; break; else k=1; if (k=1) rowPassOne(); if (xi) for (j=x+1;j=i;j+ ) if (gridjy!=0) k=0; break; else k=1; if (k=1) rowPassOne(); if (x=i) rowPassOne(); if (k=2) if (y0=y) remove(); if (y0y) for (n=y0;ny) for (n=y0;n=y+1 ;n-) if (gridin!=0) k=0; break; if(gri

21、din=0 & n=y+1) remove(); public void linePassOne() if (y0j) /第一按钮同行空按钮在左边 for (i=y0-1;i=j ;i- ) /判断第一按钮同左侧空按钮之间有没按钮 if (gridx0i!=0) k=0; break; else k=2; /K=2说明通过了第二次验证 if (y0j) /第一按钮同行空按钮在与第二按钮之间 for (i=y0+1;ii) for (j=x0-1;j=i ;j- ) if (gridjy0!=0) k=0; break; else k=2; if (x0i) for (j=x0+1;j=i ;j

22、+ ) if (gridjy0!=0) k=0; break; else k=2; public void remove() firstButton.setVisible(false); secondButton.setVisible(false); fraction(); pressInformation=false; k=0; gridx0y0=0; gridxy=0; public void actionPerformed(ActionEvent e) if(e.getSource()=newlyButton) int grid = new int87; this.grid = grid

23、; randomBuild(); mainFrame.setVisible(false); pressInformation=false; init(); if(e.getSource()=exitButton) System.exit(0); if(e.getSource()=resetButton) reload(); for(int cols = 0;cols 6;cols+) for(int rows = 0;rows 5;rows+ ) if(e.getSource()=diamondsButtoncolsrows) estimateEven(cols+1,rows+1,diamon

24、dsButtoncolsrows); public static void main(String args) /主方法lianliankan llk = new lianliankan(); /实例化llk.randomBuild(); /调用llk.init(); 关节点:a. Java的接口技术b. Java的事件处理机制c. Java的布局管理 (四):总结通过java这次实训学习,我从中学到了许多新的知识,而且通过这次实训设计,培养了我从多门课程中获取知识、迅速规划并开发出目标系统的能力,也锻炼了我们团队合作协调的能力,以及编程能力也有了很大的提高。另外也有许多心得体会,在系统开发过程真的很艰难,也非常辛苦,特别是其中不得不做一些功能性甚至系统结构性方面的变动,将面对许多重复枯燥性的工作。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1