JAVA课程设计连连看最终版要点Word文件下载.docx

上传人:b****6 文档编号:19962154 上传时间:2023-01-12 格式:DOCX 页数:15 大小:55.39KB
下载 相关 举报
JAVA课程设计连连看最终版要点Word文件下载.docx_第1页
第1页 / 共15页
JAVA课程设计连连看最终版要点Word文件下载.docx_第2页
第2页 / 共15页
JAVA课程设计连连看最终版要点Word文件下载.docx_第3页
第3页 / 共15页
JAVA课程设计连连看最终版要点Word文件下载.docx_第4页
第4页 / 共15页
JAVA课程设计连连看最终版要点Word文件下载.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

JAVA课程设计连连看最终版要点Word文件下载.docx

《JAVA课程设计连连看最终版要点Word文件下载.docx》由会员分享,可在线阅读,更多相关《JAVA课程设计连连看最终版要点Word文件下载.docx(15页珍藏版)》请在冰豆网上搜索。

JAVA课程设计连连看最终版要点Word文件下载.docx

1)init()方法:

实现游戏主界面;

2)randomBuild()方法:

用来产生游戏按钮上的随机数;

3)fraction()方法:

游戏界面最上面用来加分;

4)reload()方法:

用来刷新,重载,窗体界面;

5)estimateEven()方法:

判断按钮数字是否满足消去的条件linePassOne()方法:

判断第一按钮同左右侧空按钮之间

rowPassOne()方法:

判断第一按钮同列空按钮与第二按钮;

6)actionPerformed(ActionEvente)方法:

用来实现重来一

局按钮的响应事件;

7)main(String[]args)方法:

主函数;

8)xiao()方法:

消去方法

(三):

界面要求:

用图形界面实现,参考下

系统流程图如下

 

(四):

代码设计

package数字版;

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

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

如果不能消除完,便可以按重列,

这样会把剩余的重新排列。

便可以继续玩了,

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

*/

importjavax.swing.*;

//调用图形界面类布局

importjava.awt.*;

importjava.awt.event.*;

publicclasslianliankanimplementsActionListener

{//继承一个监听器

JFramemainFrame;

//游戏主面板用布局管理器

ContainerthisContainer;

//一个容器

JPanelcenterPanel,southPanel,northPanel;

//子面板

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

//游戏按钮数组

JButtonexitButton,resetButton,newlyButton;

//退出,重列,重新开始按钮

JLabelfractionLable=newJLabel("

0"

);

//分数标签显示您玩游戏得了多少分!

JButtonfirstButton,secondButton;

//分别记录两次被选中的按钮

intgrid[][]=newint[8][7];

//储存游戏按钮位置

staticbooleanpressInformation=false;

//判断是否有按钮被选中

intx0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV;

//游戏按钮的位置坐标

inti,j,k,n;

//消除方法控制

publicvoidinit(){

mainFrame=newJFrame("

数字版连连看"

thisContainer=mainFrame.getContentPane();

thisContainer.setLayout(newBorderLayout());

//setLayout()设置用户界面上的屏幕组件的格式布局,是java图形界面编程的常用方法。

此处是方位布局

centerPanel=newJPanel();

//中间部分(用来放游戏显示内容)

southPanel=newJPanel();

//下面部分(用来放退出,重列,重新开始按钮)

northPanel=newJPanel();

//上面部分(用来记录得分情况)

centerPanel.setBackground(newColor(145,145,44));

//灰色

northPanel.setBackground(newColor(245,252,252));

//颜色red

thisContainer.add(centerPanel,"

Center"

thisContainer.add(southPanel,"

South"

thisContainer.add(northPanel,"

North"

centerPanel.setLayout(newGridLayout(6,5));

//设置游戏图标

for(intcols=0;

cols<

6;

cols++){

for(introws=0;

rows<

5;

rows++){

diamondsButton[cols][rows]=newJButton(String.valueOf(grid[cols+1][rows+1]));

//换下一行

diamondsButton[cols][rows].setBackground(newColor(199,190,33));

//颜色

diamondsButton[cols][rows].setFont(newjava.awt.Font("

黑体"

1,22));

diamondsButton[cols][rows].setBorder(BorderFactory.createLoweredBevelBorder());

diamondsButton[cols][rows].addActionListener(this);

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

}

exitButton=newJButton("

退出"

exitButton.setFont(newjava.awt.Font("

1,16));

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

exitButton.setBorder(BorderFactory.createRaisedBevelBorder());

exitButton.setBackground(newColor(25,155,100));

//颜色绿色

exitButton.addActionListener(this);

resetButton=newJButton("

刷新"

resetButton.setFont(newjava.awt.Font("

resetButton.setPreferredSize(newDimension(55,30));

resetButton.setBorder(BorderFactory.createRaisedBevelBorder());

resetButton.setBackground(newColor(77,175,100));

//蓝色

resetButton.addActionListener(this);

newlyButton=newJButton("

再来一局"

newlyButton.setFont(newjava.awt.Font("

newlyButton.setPreferredSize(newDimension(100,33));

newlyButton.setBorder(BorderFactory.createRaisedBevelBorder());

newlyButton.setBackground(newColor(255,192,203));

//粉色

newlyButton.addActionListener(this);

//添加了监听器!

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

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

//用来计算得分数,不断变化

northPanel.add(fractionLable);

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

mainFrame.setVisible(true);

publicvoidrandomBuild(){//产生随机数

intrandoms,cols,rows;

for(inttwins=1;

twins<

=15;

twins++){

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

for(intalike=1;

alike<

=2;

alike++){

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

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

while(grid[cols][rows]!

=0){

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

publicvoidfraction(){

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));

publicvoidreload(){

intsave[]=newint[30];

intn=0,cols,rows;

intgrid[][]=newint[8][7];

//双重循环,输出二维数组!

for(inti=0;

i<

=6;

i++){

for(intj=0;

j<

=5;

j++){

if(this.grid[i][j]!

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

n++;

n=n-1;

this.grid=grid;

while(n>

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

n--;

mainFrame.setVisible(false);

pressInformation=false;

//这里一定要将按钮点击信息归为初始

init();

for(inti=0;

i<

i++){

for(intj=0;

j<

j++){

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

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

publicvoidestimateEven(intplaceX,intplaceY,JButtonbz){

if(pressInformation==false){

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

pressInformation=true;

else{

x0=x;

y0=y;

fristMsg=secondMsg;

firstButton=secondButton;

if(fristMsg==secondMsg&

&

secondButton!

=firstButton){

xiao();

//调用消掉的方法

publicvoidxiao(){//相同的情况下能不能消去。

仔细分析,不一条条注释

if((x0==x&

(y0==y+1||y0==y-1))||((x0==x+1||x0==x-1)&

(y0==y))){//判断是否相邻

remove();

else{

for(j=0;

7;

j++){

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

if(y>

j){//如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边

for(i=y-1;

i>

=j;

i--){//判断第二按钮左侧直到第一按钮中间有没有按钮

if(grid[x][i]!

k=0;

break;

else{k=1;

}//K=1说明通过了第一次验证

if(k==1){

linePassOne();

if(y<

j){//如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边

for(i=y+1;

=j;

i++){//判断第二按钮左侧直到第一按钮中间有没有按钮

=0){

else{k=1;

}

if(k==1){

if(y==j){

if(k==2){

if(x0==x){

if(x0<

x){

for(n=x0;

n<

=x-1;

n++){

if(grid[n][j]!

if(grid[n][j]==0&

n==x-1){

if(x0>

n>

=x+1;

n--){

n==x+1){

for(i=0;

8;

i++){//列

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

if(x>

i){

for(j=x-1;

j>

=i;

j--){

if(grid[j][y]!

rowPassOne();

if(x<

for(j=x+1;

=i;

if(x==i){

if(k==2){

if(y0==y){

if(y0<

y){

for(n=y0;

=y-1;

if(grid[i][n]!

if(grid[i][n]==0&

n==y-1){

if(y0>

=y+1;

n--){

n==y+1){

publicvoidlinePassOne(){

j){//第一按钮同行空按钮在左边

for(i=y0-1;

i--){//判断第一按钮同左侧空按钮之间有没按钮

if(grid[x0][i]!

else{k=2;

}//K=2说明通过了第二次验证

j){//第一按钮同行空按钮在与第二按钮之间

for(i=y0+1;

else{k=2;

publicvoidrowPassOne(){

for(j=x0-1;

if(grid[j][y0]!

for(j=x0+1;

publicvoidremove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

grid[x0][y0]=0;

grid[x][y]=0;

publicvoidactionPerformed(ActionEvente){

if(e.getSource()==newlyButton){

this.grid=grid;

randomBuild();

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

publicstaticvoidmain(String[]args){//主方法

lianliankanllk=newlianliankan();

//实例化

llk.randomBuild();

//调用

llk.init();

}

关节点:

a.Java的接口技术

b.Java的事件处理机制

c.Java的布局管理

(四):

总结

通过java这次实训学习,我从中学到了许多新的知识,而且通过这次实训设计,培养了我从多门课程中获取知识、迅速规划并开发出目标系统的能力,也锻炼了我们团队合作协调的能力,以及编程能力也有了很大的提高。

另外也有许多心得体会,在系统开发过程真的很艰难,也非常辛苦,特别是其中不得不做一些功能性甚至系统结构性方面的变动,将面对许多重复枯燥性的工作。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

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

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