java蔬菜连连看游戏程序设计组.docx
- 文档编号:20684798
- 上传时间:2023-04-25
- 格式:DOCX
- 页数:27
- 大小:147.59KB
java蔬菜连连看游戏程序设计组.docx
《java蔬菜连连看游戏程序设计组.docx》由会员分享,可在线阅读,更多相关《java蔬菜连连看游戏程序设计组.docx(27页珍藏版)》请在冰豆网上搜索。
java蔬菜连连看游戏程序设计组
《面向对象的程序设计》课程设计
1、题目:
蔬菜连连看游戏程序设计
2、实验目的:
通过在指定的窗口界面完成“连连看”小游戏程序的编写和调试加深对面向对象程序设计的理解
3、主要功能:
相同图片相邻或连成一条直线可消除,相同图片之间只转一个或两个弯也可消除
4、平台:
在Windows7下使用MyEclipse开发
5、设计参数:
A.该程序界面为方格类型,由纵10横10的直线交叉组成,分别是8行8列方块拼接,共64格小方块。
方块上随即分布一些数字,数字的要求是至两两相同,位置随机打乱。
B.游戏规则是将相同数字的方块连接,若连接一对成功就消失于界面,继续游戏,知道游戏结束。
C.游戏设有时间要求,时间到,游戏结束。
D.游戏可以选择难度,分别为简单,中等,较难、超难。
E.游戏有记录得分和关卡。
F.
6、设计组:
设计组名称:
蔬菜连连看游戏程序设计组
专业班级:
软件1113
人员
学号
姓名
分工
设计组长
2011813086
程秋瑜
找资料,编代码,制框架图,纠错
程序员
2011813083
王春辉
找资料,编代码,纠错
程序员
2011813087
王国林
找资料,编代码,纠错
程序员
2011813088
陈坤炜
找资料,编代码,纠错
程序员
2011813090
杨彬
找资料,编代码,纠错
7、完成情况:
a.本程序源代码保存形式为lianliankan.java,在MyEclipse工具下开发。
b.本程序由两个类构成,分别是classlianliankan和classlianliankanJPanel,其中classlianliankanJPanel是内部类。
c.本程序由画画函数painComponent()、重载函数chongzai()、重新开始游戏newGame()、所有方块清除,进入下一关guoguan()、新建地图newMap()、判断是否在一条直线上linecheck()、判断能否折角相连zhejiaocheck()、判断能否两次折角相连liangcizejiaocheck()、能否在两次折角内连接ifcanTouch()、清除两个一样的符合条件的方块clearBlock()、选择难度itemStateChanged()、主函数main()、画画函数paintCompinent()等十三个函数组成。
8、工作评价:
设计组名称:
蔬菜连连看游戏程序设计组
专业班级:
软件1113班
人员
学号
姓名
分工
设计组长
2011813086
程秋瑜
找资料,编代码,制框架图,纠错
程序员
2011813083
王春辉
找资料,编代码,纠错
程序员
2011813087
王国林
找资料,编代码,纠错
程序员
2011813088
陈坤炜
找资料,编代码,纠错
程序员
2011813090
杨彬
找资料,编代码,纠错
9、其他说明:
附上代码:
packagelianliankan;
importjava.awt.*;//java.awt包,即java抽象窗口工具包,提供如Button(按钮)、TextField(文本框)和List(列表)
importjavax.swing.*;//javax.swing是图形可视包,导入进行图形化软件的开发
importjava.awt.event.*;
publicclasslianliankanextendsJFrame
{
privatestaticfinallongserialVersionUID=1L;
publiclianliankan()
{
lianliankanJPanelllk=newlianliankanJPanel();//是个容器,可以把JButton,JTextArea,JTextFiled等加入
add(llk);
}
classlianliankanJPanelextendsJPanelimplementsActionListener,ItemListener
{
privatestaticfinallongserialVersionUID=1L;
privateint[][]map=newint[10][10];
privateintkinds,randomx,randomy,randomx1,randomy1;
privateintcoordinatex,coordinatey,coordinatex1,coordinatey1;
privatePointlineStart=newPoint(0,0);
privateintclicktimes;
privateintjishushengyu;
privateintfruitKinds=4;
privateintscore;
privateintguanshu;
loudould=newloudou();
JButtonBlockButton[][]=newJButton[10][10];
ChoicedifficultChoice=newChoice();
JButtonnewgameButton=newJButton("开始");
JButtonreLoad=newJButton("刷新");
ImageIconaIcon=newImageIcon("image/sucai1.jpg");
ImageIconbIcon=newImageIcon("image/sucai2.jpg");
ImageIconcIcon=newImageIcon("image/sucai3.jpg");
ImageIcondIcon=newImageIcon("image/sucai4.jpg");
ImageIconeIcon=newImageIcon("image/sucai5.jpg");
ImageIconfIcon=newImageIcon("image/sucai6.jpg");
ImageIcongIcon=newImageIcon("image/sucai7.jpg");
ImageIconhIcon=newImageIcon("image/sucai8.jpg");
ImageIconiIcon=newImageIcon("image/sucai9.jpg");
ImageIconjIcon=newImageIcon("image/sucai10.jpg");
ImageIconk1Icon=newImageIcon("image/sucai11.jpg");
ImageIconlIcon=newImageIcon("image/sucai12.jpg");
ImageIconmIcon=newImageIcon("image/sucai13.jpg");
ImageIconnIcon=newImageIcon("image/sucai14.jpg");
ImageIconoIcon=newImageIcon("image/sucai15.jpg");
ImageIconkIcon=newImageIcon("image/kongbai.jpg");
publiclianliankanJPanel()
{
this.setLayout(null);
newMap();
for(inti=0;i<10;i++)
{
for(intj=0;j<10;j++)
{
BlockButton[i][j]=newJButton();
add(BlockButton[i][j]);
BlockButton[i][j].addActionListener(this);
BlockButton[i][j].setBounds(j*40,i*40,40,40);
}
}
difficultChoice.add("简单");
difficultChoice.add("中等");
difficultChoice.add("较难");
difficultChoice.add("超难");
newgameButton.setBounds(map[0].length*40+30,20,60,20);
reLoad.setBounds(map[0].length*40+30,60,60,20);
difficultChoice.setBounds(map[0].length*40+30,100,60,20);
difficultChoice.addItemListener(this);
newgameButton.addActionListener(this);
reLoad.addActionListener(this);
ld.setBounds(map[0].length*40+30,240,70,160);
this.add(ld);
this.add(newgameButton);
this.add(reLoad);
this.add(difficultChoice);
}
publicvoidpaintComponent(Graphicsg)//画画函数
{
super.paintComponent(g);
g.drawString("得分:
"+score,430,160);
g.drawString("第"+(guanshu+1)+"关",430,200);
for(inti=0;i<10;i++)
{
for(intj=0;j<10;j++)
{
switch(map[i][j])
{
case0:
BlockButton[i][j].setIcon(kIcon);
break;
case1:
BlockButton[i][j].setIcon(aIcon);
break;
case2:
BlockButton[i][j].setIcon(bIcon);
break;
case3:
BlockButton[i][j].setIcon(cIcon);
break;
case4:
BlockButton[i][j].setIcon(dIcon);
break;
case5:
BlockButton[i][j].setIcon(eIcon);
break;
case6:
BlockButton[i][j].setIcon(fIcon);
break;
case7:
BlockButton[i][j].setIcon(gIcon);
break;
case8:
BlockButton[i][j].setIcon(hIcon);
break;
case9:
BlockButton[i][j].setIcon(iIcon);
break;
case10:
BlockButton[i][j].setIcon(jIcon);
break;
case11:
BlockButton[i][j].setIcon(k1Icon);
break;
case12:
BlockButton[i][j].setIcon(lIcon);
break;
case13:
BlockButton[i][j].setIcon(mIcon);
break;
case14:
BlockButton[i][j].setIcon(nIcon);
break;
case15:
BlockButton[i][j].setIcon(oIcon);
break;
default:
break;
}
}
}
}
publicvoidchongzai()//重载函数
{
jishushengyu=0;
for(inti=1;i<9;i++)
{
for(intj=1;j<9;j++)
{
if(map[i][j]>0)
{
jishushengyu++;
}
}
}
int[][]map1=newint[10][10];
this.map=map1;
for(inti=0;i { kinds=(int)(Math.random()*1000)%fruitKinds+1; do{ randomx1=(int)(Math.random()*1000)%8+1; randomy1=(int)(Math.random()*1000)%8+1; }while(map[randomy1][randomx1]>0); map[randomy1][randomx1]=kinds; do{ randomx=(int)(Math.random()*1000)%8+1; randomy=(int)(Math.random()*1000)%8+1; }while(map[randomy][randomx]>0); map[randomy][randomx]=kinds; } repaint(); } publicvoidnewGame()//重新开始游戏 { for(inti=0;i<10;i++) { for(intj=0;j<10;j++) { BlockButton[j][i].setEnabled(true); } } int[][]map=newint[10][10]; this.map=map; newMap(); ld.setTimes(0); score=0; guanshu=0; ld.setdijiguan(guanshu); } publicvoidguoguan()//过关后所有方块自动清除进行下一关 { intjishushengyu2=0; for(inti=1;i<9;i++) { for(intj=1;j<9;j++) { if(map[i][j]>0) { jishushengyu2++; } } } if(jishushengyu2==0) { int[][]map=newint[10][10]; this.map=map; newMap(); ld.setTimes(0); guanshu++; ld.setdijiguan(guanshu); reLoad.setEnabled(true); } } publicvoidnewMap()//新建地图 { for(inti=0;i<32;i++) { kinds=(int)(Math.random()*1000)%fruitKinds+1; do{ randomx1=(int)(Math.random()*1000)%8+1; randomy1=(int)(Math.random()*1000)%8+1; }while(map[randomy1][randomx1]>0); map[randomy1][randomx1]=kinds; do{ randomx=(int)(Math.random()*1000)%8+1; randomy=(int)(Math.random()*1000)%8+1; }while(map[randomy][randomx]>0); map[randomy][randomx]=kinds; } } publicbooleanlinecheck(inty1,intx1,inty2,intx2){//判断是否在一条直线上 if(y1==y2) { if(x2>x1) { intj=0; for(inti=0;i { if(map[y1][x1+i+1]>0) j++; } if(j==0) returntrue; } if(x1>x2) { intj=0; for(inti=0;i { if(map[y1][x2+i+1]>0) j++; } if(j==0) returntrue; } } if(x1==x2) { if(y2>y1) { intj=0; for(inti=0;i { if(map[y1+i+1][x1]>0) j++; } if(j==0) returntrue; } if(y1>y2) { intj=0; for(inti=0;i { if(map[y2+i+1][x1]>0) j++; } if(j==0) returntrue; } } returnfalse; } publicbooleanzhejiaocheck(inty1,intx1,inty2,intx2)//判断能否折角相连 { if(linecheck(y1,x1,y2,x1)&&linecheck(y2,x1,y2,x2)&&map[y2][x1]==0) { returntrue; } if(linecheck(y1,x1,y1,x2)&&linecheck(y1,x2,y2,x2)&&map[y1][x2]==0) { returntrue; } returnfalse; } publicbooleanliangcizhejiaocheck(inty1,intx1,inty2,intx2)//判断能否两次折角相连 { for(inti=0;i<9;i++) { if(x2+1+i<10&&map[y2][x2+1+i]==0&&linecheck(y2,x2,y2,x2+1+i)) { if(zhejiaocheck(y1,x1,y2,x2+1+i)) returntrue; } if(x2-1-i>=0&&map[y2][x2-1-i]==0&&linecheck(y2,x2,y2,x2-1-i)) { if(zhejiaocheck(y1,x1,y2,x2-1-i)) returntrue; } if(y2+1+i<10&&map[y2+1+i][x2]==0&&linecheck(y2,x2,y2+1+i,x2)) { if(zhejiaocheck(y1,x1,y2+1+i,x2)) returntrue; } if(y2-1-i>=0&&map[y2-1-i][x2]==0&&linecheck(y2,x2,y2-1-i,x2)) { if(zhejiaocheck(y1,x1,y2-1-i,x2)) returntrue; } } returnfalse; } publicbooleanifcanTouch(inty1,intx1,inty2,intx2)//能否在两次折角内连接 { if(y1==y2&&(x1==x2+1||x1==x2-1))//相邻 { returntrue; } if(x1==x2&&(y1==y2+1||y1==y2-1)) { returntrue; } if(linecheck(y1,x1,y2,x2))//一条线上 { returntrue; } if(zhejiao
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 蔬菜 连连 游戏 程序设计
![提示](https://static.bdocx.com/images/bang_tan.gif)