小游戏俄罗斯方块代码.docx
- 文档编号:25893832
- 上传时间:2023-06-16
- 格式:DOCX
- 页数:29
- 大小:18.34KB
小游戏俄罗斯方块代码.docx
《小游戏俄罗斯方块代码.docx》由会员分享,可在线阅读,更多相关《小游戏俄罗斯方块代码.docx(29页珍藏版)》请在冰豆网上搜索。
小游戏俄罗斯方块代码
东西绝对不多说,直接看!
看了拷贝就懂了!
!
,直接可以拷贝下面的东西,然后记得把那个BLOCK的名字改成你自己的类名,这个很关键哦,不然是错的可别怪我,呵呵~~
import.*;
import.*;
import.*;
import.*;
import.*;
publicclassBlockextendsJPanelimplementsActionListener,KeyListenerddActionListener(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);
(320,15,30,20);
(360,15,160,20);
;
(320,45,30,20);
(360,45,160,20);
;
but[1].setEnabled(false);
but[4].setEnabled(false);
(320,75,30,20);
(360,75,160,20);
;
(360,360,160,25);
(this);
(this);
(this);
(this);
(this);
num_csh_game();
rand_block();
}
publicvoidactionPerformed(ActionEvente)
{
if()==but[0])etEnabled(false);
but[1].setEnabled(true);
but[4].setEnabled(true);
();
}
if()==but[1]||()==mi0)etEnabled(true);
but[1].setEnabled(false);
but[4].setEnabled(false);
}
if()==but[2])//降低级数
{
("降低级数!
");
speedMark--;
if(speedMark<=1)
{
speedMark=1;
("已经是最低级数!
");
}
(speedMark+"");
}
if()==but[3])//提高级数
{
("提高级数!
");
speedMark++;
if(speedMark>=9)
{
speedMark=9;
("已经是最高级数!
");
}
(speedMark+"");
}
if()==but[4])//游戏暂停
{
(noStop);
(but[4]);
("游戏暂停!
");
();
}
if()==noStop)//取消暂停
{
(noStop);
(but[4]);
("继续游戏!
");
();
}
if()==but[5]||()==mi1)//退出游戏
{
();
}
if()==mi1_0)//退出游戏
{
dlg_1=newJDialog(jf,"关于");
try{
FileInputStreamio=newFileInputStream("resource/");//得到路径
bytea[]=newbyte[()];
(a);
();
Stringstr=newString(a);
(str);
}
catch(Exceptiong){}
(false);
(dlg_1_text);
();
(false);
(200,120);
(400,240);
();
}
}
publicvoidrand_block()//随机产生砖块
{
intnum;
num=(int)()*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;
("游戏进行中!
");
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;
("游戏进行中!
");
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;
("游戏进行中!
");
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;
("游戏进行中!
");
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;
("游戏进行中!
");
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;
("游戏进行中!
");
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;
("游戏进行中!
");
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;
("游戏进行中!
");
repaint();
}
}
if(game_sign_x[0]==game_sign_x[2]&&game_sign_x[0]==game_sign_x[3]&&game_sign_y[1]==game_sign_y[2]&&game_sign_x[0]>=2)
{
if(game_body[game_sign_y[0]][game_sign_x[0]-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]-2]=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;
("游戏进行中!
");
repaint();
}
}
if(game_sign_y[0]==game_sign_y[1]&&game_sign_y[0]==game_sign_y[2]&&game_sign_x[1]==game_sign_x[3]&&game_sign_y[0]<=16)
{
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
[2]][game_sign_x[2]-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]-2]=1;
game_body[game_sign_y[3]][game_sign_x[3]]=1;
("游戏进行中!
");
repaint();
}
}
}
if(blockNumber==5&&downSign==false)//变换转弯3有4种情况
{
if(game_sign_x[0]==game_sign_x[2]&&game_sign_x[2]==game_sign_x[3]&&game_sign_y[0]==game_sign_y[1]&&game_sign_x[1]>=2)
{
if(game_body[game_sign_y[0]+1][game_sign_x[0]-1]!
=2&&game_body[game_sign_y[1]][game_sign_x[1]-2]!
=2&&game_body[game_sign_y
[3]-1][game_sign_x[3]+1]!
=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]-2]=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;
("游戏进行中!
");
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[1]&&game_sign_y[0]<=16)
{
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;
("游戏进行中!
");
repaint();
}
}
if(game_sign_x[0]==game_sign_x[1]&&game_sign_x[1]==game_sign_x[3]&&game_sign_y[2]==game_sign_y[3])
{
if(game_body[game_sign_y[0]+1][game_sign_x[0]-1]!
=2&&game_body[game_sign_y[2]][game_sign_x[2]+2]!
=2&&game_body[game_sign_y
[3]-1][game_sign_x[3]+1]!
=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]][game_sign_x[2]+2]=1;
game_body[game_sign_y[3]-1][game_sign_x[3]+1]=1;
("游戏进行中!
");
repaint();
}
}
if(game_sign_y[0]==game_sign_y[1]&&game_sign_y[1]==game_sign_y[2]&&game_sign_x[2]==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_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 小游戏 俄罗斯方块 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)