小游戏俄罗斯方块代码JAVA.docx

上传人:b****2 文档编号:3425846 上传时间:2023-05-05 格式:DOCX 页数:33 大小:20.23KB
下载 相关 举报
小游戏俄罗斯方块代码JAVA.docx_第1页
第1页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第2页
第2页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第3页
第3页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第4页
第4页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第5页
第5页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第6页
第6页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第7页
第7页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第8页
第8页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第9页
第9页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第10页
第10页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第11页
第11页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第12页
第12页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第13页
第13页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第14页
第14页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第15页
第15页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第16页
第16页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第17页
第17页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第18页
第18页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第19页
第19页 / 共33页
小游戏俄罗斯方块代码JAVA.docx_第20页
第20页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

小游戏俄罗斯方块代码JAVA.docx

《小游戏俄罗斯方块代码JAVA.docx》由会员分享,可在线阅读,更多相关《小游戏俄罗斯方块代码JAVA.docx(33页珍藏版)》请在冰点文库上搜索。

小游戏俄罗斯方块代码JAVA.docx

小游戏俄罗斯方块代码JAVA

东西绝对不多说,直接看!

看了拷贝就懂了!

,直接可以拷贝下面的东西,然后记得把那个BLOCK的名字改成你自己的类名,这个很关键哦,不然是错的可别怪我,呵呵~~

importjava.awt.*;

importjava.awt.event.*;

importjavax.swing.*;

importjava.applet.*;

importjava.lang.String.*;

importjava.lang.*;

importjava.io.*;

publicclassBlockextendsJPanelimplementsActionListener,KeyListener//应该是继承JPanel

{

staticButtonbut[]=newButton[6];

staticButtonnoStop=newButton("取消暂停");

staticLabelscoreLab=newLabel("分数:

");

staticLabelinfoLab=newLabel("提示:

");

staticLabelspeedLab=newLabel("级数:

");

staticLabelscoreTex=newLabel("0");

staticLabelinfoTex=newLabel("");

staticLabelspeedTex=newLabel("1");

staticJFramejf=newJFrame();

staticMyTimertimer;

staticImageIconicon=newImageIcon("resource/Block.jpg");

staticJMenuBarmb=newJMenuBar();

staticJMenumenu0=newJMenu("游戏");

staticJMenumenu1=newJMenu("帮助");

staticJMenuItemmi0=newJMenuItem("新游戏");

staticJMenuItemmi1=newJMenuItem("退出");

staticJMenuItemmi1_0=newJMenuItem("关于");

staticJDialogdlg_1;

staticJTextAreadlg_1_text=newJTextArea();

staticintstartSign=0;//游戏开始标志0未开始1开始2暂停

staticStringbutLab[]={"开始游戏","重新开始","降低级数","提高级数","游戏暂停","退出游戏"};

staticintgame_body[][]=newint[19][10];

staticintgame_sign_x[]=newint[4];//用于记录4个方格的水平位置

staticintgame_sign_y[]=newint[4];//用于记录4个方格的垂直位置

staticbooleandownSign=false;//是否落下

staticintblockNumber=1;//砖块的编号

staticintgameScore=0;//游戏分数

staticintspeedMark=1;

publicstaticvoidmain(Stringargs[])

{

BlockmyBlock=newBlock();

mb.add(menu0);

mb.add(menu1);

menu0.add(mi0);

menu0.add(mi1);

menu1.add(mi1_0);

jf.setJMenuBar(mb);

myBlock.init();

jf.add(myBlock);

jf.setSize(565,501);

jf.setResizable(false);

jf.setTitle("俄罗斯方块");

jf.setIconImage(icon.getImage());

jf.setLocation(200,100);

jf.show();

timer=newMyTimer(myBlock);//启动线程

timer.setDaemon(true);

timer.start();

timer.suspend();

}

publicvoidinit()

{

setLayout(null);

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

{

but[i]=newButton(butLab[i]);

add(but[i]);

but[i].addActionListener(this);

but[i].addKeyListener(this);

but[i].setBounds(360,(240+30*i),160,25);

}

add(scoreLab);

add(scoreTex);

add(speedLab);

add(speedTex);

add(infoLab);

add(infoTex);

add(scoreLab);

scoreLab.setBounds(320,15,30,20);

scoreTex.setBounds(360,15,160,20);

scoreTex.setBackground(Color.white);

speedLab.setBounds(320,45,30,20);

speedTex.setBounds(360,45,160,20);

speedTex.setBackground(Color.white);

but[1].setEnabled(false);

but[4].setEnabled(false);

infoLab.setBounds(320,75,30,20);

infoTex.setBounds(360,75,160,20);

infoTex.setBackground(Color.white);

noStop.setBounds(360,360,160,25);

noStop.addActionListener(this);

noStop.addKeyListener(this);

mi0.addActionListener(this);

mi1.addActionListener(this);

mi1_0.addActionListener(this);

num_csh_game();

rand_block();

}

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==but[0])//开始游戏

{

startSign=1;

infoTex.setText("游戏已经开始!

");

but[0].setEnabled(false);

but[1].setEnabled(true);

but[4].setEnabled(true);

timer.resume();

}

if(e.getSource()==but[1]||e.getSource()==mi0)//重新开始游戏

{

startSign=0;

gameScore=0;

timer.suspend();

num_csh_restart();

repaint();

rand_block();

scoreTex.setText("0");

infoTex.setText("新游戏!

");

but[0].setEnabled(true);

but[1].setEnabled(false);

but[4].setEnabled(false);

}

if(e.getSource()==but[2])//降低级数

{

infoTex.setText("降低级数!

");

speedMark--;

if(speedMark<=1)

{

speedMark=1;

infoTex.setText("已经是最低级数!

");

}

speedTex.setText(speedMark+"");

}

if(e.getSource()==but[3])//提高级数

{

infoTex.setText("提高级数!

");

speedMark++;

if(speedMark>=9)

{

speedMark=9;

infoTex.setText("已经是最高级数!

");

}

speedTex.setText(speedMark+"");

}

if(e.getSource()==but[4])//游戏暂停

{

this.add(noStop);

this.remove(but[4]);

infoTex.setText("游戏暂停!

");

timer.suspend();

}

if(e.getSource()==noStop)//取消暂停

{

this.remove(noStop);

this.add(but[4]);

infoTex.setText("继续游戏!

");

timer.resume();

}

if(e.getSource()==but[5]||e.getSource()==mi1)//退出游戏

{

jf.dispose();

}

if(e.getSource()==mi1_0)//退出游戏

{

dlg_1=newJDialog(jf,"关于");

try{

FileInputStreamio=newFileInputStream("resource/guanyu.txt");//得到路径

bytea[]=newbyte[io.available()];

io.read(a);

io.close();

Stringstr=newString(a);

dlg_1_text.setText(str);

}

catch(Exceptiong){}

dlg_1_text.setEditable(false);

dlg_1.add(dlg_1_text);

dlg_1.pack();

dlg_1.setResizable(false);

dlg_1.setSize(200,120);

dlg_1.setLocation(400,240);

dlg_1.show();

}

}

publicvoidrand_block()//随机产生砖块

{

intnum;

num=(int)(Math.random()*6)+1;//产生0~6之间的随机数

blockNumber=num;

switch(blockNumber)

{

case1:

block1();blockNumber=1;break;

case2:

block2();blockNumber=2;break;

case3:

block3();blockNumber=3;break;

case4:

block4();blockNumber=4;break;

case5:

block5();blockNumber=5;break;

case6:

block6();blockNumber=6;break;

case7:

block7();blockNumber=7;break;

}

}

publicvoidchange_body(intblockNumber)//改变砖块状态

{

dingwei();

if(blockNumber==1&&downSign==false)//变换长条2种情况

{

if(game_sign_y[0]==game_sign_y[1]&&game_sign_y[3]<=16)//说明长条是横着的

{

if(game_body[game_sign_y[0]-1][game_sign_x[0]+1]!

=2&&game_body[game_sign_y[3]+2][game_sign_x[3]-2]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]-1][game_sign_x[0]+1]=1;

game_body[game_sign_y[1]][game_sign_x[1]]=1;

game_body[game_sign_y[2]+1][game_sign_x[2]-1]=1;

game_body[game_sign_y[3]+2][game_sign_x[3]-2]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

if(game_sign_x[0]==game_sign_x[1]&&game_sign_x[0]>=1&&game_sign_x[3]<=7)//说明长条是竖着的

{

if(game_body[game_sign_y[0]+1][game_sign_x[0]-1]!

=2&&game_body[game_sign_y[3]-2][game_sign_x[3]+2]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]+1][game_sign_x[0]-1]=1;

game_body[game_sign_y[1]][game_sign_x[1]]=1;

game_body[game_sign_y[2]-1][game_sign_x[2]+1]=1;

game_body[game_sign_y[3]-2][game_sign_x[3]+2]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

}

if(blockNumber==3&&downSign==false)//变换转弯1有4种情况

{

if(game_sign_x[0]==game_sign_x[1]&&game_sign_x[0]==game_sign_x[2]&&game_sign_y[2]==game_sign_y[3]&&game_sign_x[0]>=1)

{

if(game_body[game_sign_y[0]+1][game_sign_x[0]-1]!

=2&&game_body[game_sign_y[2]-1][game_sign_x[2]+1]!

=2&&game_body

[game_sign_y[3]-2][game_sign_x[3]]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]+1][game_sign_x[0]-1]=1;

game_body[game_sign_y[1]][game_sign_x[1]]=1;

game_body[game_sign_y[2]-1][game_sign_x[2]+1]=1;

game_body[game_sign_y[3]-2][game_sign_x[3]]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

if(game_sign_y[1]==game_sign_y[2]&&game_sign_y[2]==game_sign_y[3]&&game_sign_x[0]==game_sign_x[3]&&game_sign_y[1]<=17)

{

if(game_body[game_sign_y[0]][game_sign_x[0]-2]!

=2&&game_body[game_sign_y[1]+1][game_sign_x[1]+1]!

=2&&game_body[game_sign_y

[3]-1][game_sign_x[3]-1]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]][game_sign_x[0]-2]=1;

game_body[game_sign_y[1]+1][game_sign_x[1]+1]=1;

game_body[game_sign_y[2]][game_sign_x[2]]=1;

game_body[game_sign_y[3]-1][game_sign_x[3]-1]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

if(game_sign_x[1]==game_sign_x[2]&&game_sign_x[1]==game_sign_x[3]&&game_sign_y[0]==game_sign_y[1]&&game_sign_x[3]<=8)

{

if(game_body[game_sign_y[0]+2][game_sign_x[0]]!

=2&&game_body[game_sign_y[1]+1][game_sign_x[1]-1]!

=2&&game_body[game_sign_y

[3]-1][game_sign_x[3]+1]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]+2][game_sign_x[0]]=1;

game_body[game_sign_y[1]+1][game_sign_x[1]-1]=1;

game_body[game_sign_y[2]][game_sign_x[2]]=1;

game_body[game_sign_y[3]-1][game_sign_x[3]+1]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

if(game_sign_y[0]==game_sign_y[1]&&game_sign_y[1]==game_sign_y[2]&&game_sign_x[0]==game_sign_x[3])

{

if(game_body[game_sign_y[0]+1][game_sign_x[0]+1]!

=2&&game_body[game_sign_y[2]-1][game_sign_x[2]-1]!

=2&&game_body

[game_sign_y[3]][game_sign_x[3]+2]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]+1][game_sign_x[0]+1]=1;

game_body[game_sign_y[1]][game_sign_x[1]]=1;

game_body[game_sign_y[2]-1][game_sign_x[2]-1]=1;

game_body[game_sign_y[3]][game_sign_x[3]+2]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

}

if(blockNumber==4&&downSign==false)//变换转弯2有4种情况

{

if(game_sign_x[0]==game_sign_x[1]&&game_sign_x[0]==game_sign_x[3]&&game_sign_y[1]==game_sign_y[2]&&game_sign_x[3]<=7)

{

if(game_body[game_sign_y[0]+2][game_sign_x[0]]!

=2&&game_body[game_sign_y[1]+1][game_sign_x[1]+1]!

=2&&game_body[game_sign_y

[3]][game_sign_x[3]+2]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]+2][game_sign_x[0]]=1;

game_body[game_sign_y[1]+1][game_sign_x[1]+1]=1;

game_body[game_sign_y[2]][game_sign_x[2]]=1;

game_body[game_sign_y[3]][game_sign_x[3]+2]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

if(game_sign_y[1]==game_sign_y[2]&&game_sign_y[1]==game_sign_y[3]&&game_sign_x[0]==game_sign_x[2])

{

if(game_body[game_sign_y[1]][game_sign_x[1]+2]!

=2&&game_body[game_sign_y[2]-1][game_sign_x[2]+1]!

=2&&game_body[game_sign_y

[3]-2][game_sign_x[3]]!

=2)

{

num_csh_game();

game_body[game_sign_y[0]][game_sign_x[0]]=1;

game_body[game_sign_y[1]][game_sign_x[1]+2]=1;

game_body[game_sign_y[2]-1][game_sign_x[2]+1]=1;

game_body[game_sign_y[3]-2][game_sign_x[3]]=1;

infoTex.setText("游戏进行中!

");

repaint();

}

}

if(game_sign_x[0]==ga

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

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2