JAVA课程设计-连连看要点_第1页
JAVA课程设计-连连看要点_第2页
JAVA课程设计-连连看要点_第3页
JAVA课程设计-连连看要点_第4页
JAVA课程设计-连连看要点_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

JAVA课程设计报告

试验题目:“连连看”嬉戏程序设计

小组成员:王飞铭、毛建平、陈银银、黄庭威

成员分工:

组长:王飞铭

王飞铭:actionPerformed():重来一局按钮的响应事务及

remove()推断移去方法

毛建平:xiao()消去方法、estimateEven()方法

陈银银:init()方法:嬉戏主界面和main()方法实现

黄庭威:randomBuild()产生随机数方法、fraction()刷新方

(一):内容:

1:功能需求和分析:

(1)该嬉戏界面为:数字方格类型,由6竖7横的直线平行垂直

交叉而组成,分别是6行5列凹方块拼接,共有30格小方块。方块

上随机分布一些数字,数字的要求是至少两两相同,位置随机打乱。

(2)嬉戏规则是:将相同数字的方块连接,但要满意只能至少单

边无阻碍呈直线趋势连接,否则视为无效,假如一对数字连接胜利,

那么就会消逝在界面,并且分数标签会加分,接着嬉戏,直到嬉戏结

束。

(3)帮助项目:在嬉戏过程中,假如出现没有可以连接的数字对时

候,可按界面下方按钮刷新重新排列,便可以可接着嬉戏。

(4)退出嬉戏:可以鼠标点击“退出”按钮,结束嬉戏。

(5)再来一局:本局结束或者中途不想接着玩本局,可以点击界

面下方的再来一局,系统会自动再次重新起先。

(二):主要方法:

首先我们定义了一个lianliankan类,实现了接口

ActionListener:

1)init()方法:实现嬉戏主界面;

2)randomBuildO方法:用来产生嬉戏按钮上的随机数;

3)fraction()方法:嬉戏界面最上面用来加分;

4)reloacl()方法:用来刷新,重载,窗体界面;

5)estimateEven()方法:推断按钮数字是否满意消去的条件

linePassOne()方法:推断第一按钮同左右侧空按钮之间⑦

rowPassOnc()方法:推断第一按钮同列空按钮与其次按钮;

6)actionPerformed(ActionEvente)方法:用来实现重来一

局按钮的响应事务;

7)main(String[]args)方法:主函数;

8)xia。()方法:消去方法

(三):界面要求:用图形界面实现,参考下

数字版连连看口X

0

15113718

13712716

7723223

181516147

202031418

2181312

退出|刷新|再来一局

系统流程图如下

(四):代码设计

package数字版;

/**本嬉戏是连连看,上面出现的都是数字,

点击两个相邻的或者之间没有第三个的,便可以消去。。。

假如不能消退完,便可以按重列,

这样会把剩余的重新排列。便可以接着玩了,

或者您可以按重置,重新再来一局!!!!*/

importjavax.swing.*;//调用图形界面类布局

importjava.awt.*;

importjava.awt.event.*;

publicclasslianliankanimplementsActionListener

{//继承一个监听器

JFramemainFrame;//嬉戏主面板用布局管理器

ContainerthisContainer;//一个容器

JPanelcenterPanel,southPanel,northPanel;//子面板

JButtondiamondsButton[][]=newJButton[6][5];//

嬉戏按钮数组

JButtonexitButton,resetButton,newlyButton;//退出,

重列,重新起先按钮

JLabelfractionLable=newJLabel(n0");//分数标签显

示您玩嬉戏得了多少分!!!!!!!!)

JButtonfirstButtonzsecondButton;//分别记录两次被选

中的按钮

intgrid[][]=newint[8][7];//储存嬉戏按钮位置

staticbooleanpressInformation=false;//推断是否有

按钮被选中

int

x0=0zy0=0zx=0,y=0zfristMsg=0,secondMsg=Ozvalidate

LV;//嬉戏按钮的位置坐标

inti,j,k,n;//消退方法限制

publicvoidinit(){

mainFrame-newJFramo("数字版连连看”);

thisContainer=mainFrame.getContentPane();

thisContainer.setLayout(newBorderLayout());

//setLayout()设置用户界面上的屏幕组件的格式布局,是java

图形界面编程的常用方法。此处是方位布局

centerPanel=newJPanel();//中间部分(用来放嬉戏显示内

容)

southPanel=newJPanel();//下面部分(用来放退出,重歹U,

重新起先按钮)

northPanel=newJPanel();//上面部分(用来记录得分状况)

centerPanel.setBackground(new

Color(145,145,44))”/灰色

northPanel.setBackground(new

Color(245,252,252))”/颜色red

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,HNorthn);

centerPanel.setLayout(newGridLayout(6,5));//设置

嬉戏图标

for(intcols=0;cols<6;cols++){

for(introws=0;rows<5;rows++){

diamondsButton[cols][rows]=new

JButton(String.valueOf(grid[cols+1][rows+1]));//

换下一行

diamondsButton[cols][rows].setBackground(new

Color(199,190,33));〃颜色

diamondsButton[cols][rows].setFont(new

java・awt・Font("黑体”,1,22));

diamondsButton[cols][rows].setBorder(BorderFactor

y.createLoweredBevelBorder());

diamondsButton[cols][rows].addActionListener(this

);

centerPanel.add(diamondsButton[cols][rows]);

)

}

exitButton=newJButton("退出");

exitButton.setFont(newjava.awt.Font(n黑体”,1,

16));

exitButton.setPraferredSize(newDimension(55,30));

exitButton.setBorder(BorderFactory.createRaisedBe

velBorder());

exitButton.setBackground(newColor(25,155f100));//

颜色绿色

exitButton.addActionListener(this);

resetButton=newJButton("刷新“);

resetButton.setFont(newjava.awt.Font(“黑体”,1,

16));

resetButton.setPreferredSize(new

Dimension(55,30));

resetButton.setBorder(BorderFactory.createRaisedB

evelBorder());

resetButton.setBackground(newColor(77,

175,100));〃蓝色

resetButton.addActionListener(this);

newlyButton=newJButton("再来一局”);

newlyButton.setFont(newjava.awt.Font("黑体,1,

16));

newlyButton.setPreferredSize(new

Dimension(100,33));

newlyButton.setBorder(BorderFactory.createRaisedB

evelBorder());

newlyButton.setBackground(new

Color(255,192,203));//粉色

newlyButton.addActionListener(this);//添力口了监听

器!!!!!!当点击时候,用那个来通知

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.pars

elnt(fractionLable.getText())));

//用来计算得分数,大断改变

northPanel.add(fractionLable);

mainFrame.setBounds(300,100,500,450);

mainFrame.setVisible(true);

}

publicvoidrandomBuild(){//产生随机数

intrandoms,cols,rows;

for(inttwins=l;twins<=15;twins++){

randoms=(int)(Math.random()*25+1);

for(intalike=l;alike<=2;alike++){

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0){

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

)

this.grid[cols][rows]=randoms;

)

)

}

publicvoidfraction(){

fractionLable.setText(String.valueOf(Integer.pars

elnt(fractionLable.getText())+100));

publicvoidreload(){

intsave[]=newint[30];

intn=0zcols,rows;

intgrid[][]=newint[8][7];//双重循环,输出二维数组!!!

for(inti=0;i<=6;i++){

for(intj=0;j<=5;j++){

if(this.grid[i][j]!=0){

save[n]=this.grid[i][j];

n++;

}

)

}

n=n-l;

this.grid=grid;

while(n>=0){

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0){

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

this.grid[cols][rows]=save[n];

n——;

)

mainFrame.setVisible(false);

pressinformation=false;//这里肯定要将按钮点击信息归为

初始

init();

for(inti=0;i<6;i++){

for(intj=0;j<5;j++){

if(grid[i+1][j+1]==0)

diamondsButton[i][j].setVisible(false);

)

}

)

publicvoidestimateEven(intplaceX,int

placeY,JButtonbz){

if(presslnformation==falso){

x=placeX;

y=placeY;

secondMsg=grici[x][y];

secondButton=bz;

pressInformation=true;

else{

xO=x;

yO=y;

fristMsg=secondMsg;

firstButton=secondButton;

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

if(fristMsg==secondMsg&&

secondButton!=firstButton){

xiao();//调用消掉的方法

)

)

}

publicvoidxiao(){//相同的状况下能不能消去。细致分析,

不一条条注释

if((xO==x&&(yO==y+l||yO==y-l))||

((xO==x+l||xO==x-l)&&(yO==y))){//推断是否相令B

remove();

else{

for(j=0;j<7;j++){

if(grid[xO][j]==0){//推断第一个按钮同行哪个按钮为空

if(y>j){//假如其次个按钮的Y坐标大于空按钮的Y坐标说明

第一按钮在其次按钮左边

for(i=y-l;i>=j;i―){//推断其次按钮左侧直到第一按钮中

间有没有按钮

if(grid[x][i]!=0){

k=0;

break;

}

else{k=l;)//K=l说明通过了第一次验证

}

if(k==l){

linePassOne();

}

)

if(y<j){//假如其次个按钮的Y坐标小于空按钮的Y坐标说明

第一按钮在其次按钮右边

tor(i=y+l;i<=j;i++){//推断其次按钮左侧直到第一按钮

中间有没有按钮

if(grid[x][i]!=0){

k=0;

break;

)

else{k=l;}

}

if(k==l){

linePassOne();

}

)

if(y==j){

linePassOne();

)

}

if(k==2){

if(xO==x){

remove();

)

if(xO<x){

for(n=xO;n<=x-l;n++

if(grid[n][j]!=0){

k=0;

break;

}

if(grid[n][j]==0&&n==x-l)

remove();

}

}

)

if(xO>x){

for(n=xO;n>=x+l;n--){

if(grid[n][j]!=0){

k=0;

break;

)

if(grid[n][j]==0&&n==x+l)

remove();

)

}

)

)

}

for(i=0;i<8;i++){//歹U

if(grid[i][y0]==0){

if(x>i){

for(j=x-l;j>=i;j--)

if(grid[j][y]!=0){

k=0;

break;

}

else{k=l;}

}

if(k==l){

rowPassOne();

}

}

if(x<i){

for(j=x+l;j<=i;j++){

if(grid[j][y]!=0){

k=0;

break;

)

else{k=l;}

}

if(k==l){

rowPassOne();

}

}

if(x==i){

rowPassOne();

}

}

if(k==2){

if(yO==y){

remove();

)

if(yO<y){

for(n=yO;n<=y-l;n++){

if(grid[i][n]!=0){

k=0;

break;

)

if(grid[i][n]==0&&n==y-l){

remove();

)

}

)

if(yO>y){

for(n=yO;n>=y+l;n--){

if(grid[i][n]!=0){

k=0;

break;

}

if(grid[i][n]==0&&n==y+l){

remove();

}

}

)

}

}

)

}

publicvoidlinePassOne(){

if(yO>j){//第一按钮同行空按钮在左边

for(i=yO-l;i>=j;i—){//推断第一按钮同左侧空按钮之

间有没按钮

if(grid[xO][i]]=0){

k=0;

break;

)

else{k=2;}//K=2说明通过了其次次验证

)

if(yO<j){//第一按钮同行空按钮在与其次按钮之间

for(i=yO+l;i<=j;i++){

if(grid[xO][i]!=0){

k=0;

break;

}

else{k=2;}

}

}

)

publicvoidrowPassOne(){

if(x0>i){

for(j=x0-l;j>=i;j—){

if(grid[j][yO]!=0){

k=0;

break;

}

else{k=2;}

)

if(xO<i){

for(j=xO+l;j<=i;j++){

if(grid[j][yO]!=0){

k=0;

break;

)

else{k=2;}

}

)

}

publicvoidremove(){

firstButton.setVisible(false);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论