版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、东西绝对不多说,直接看!看了拷贝就懂了!!,直接可以拷贝下面的东西,然后记得把那个BLOCK的名字改成你自己的类名,这个很关键哦,不然是错的可别怪我,呵呵import java.awt.*;importjava.awt.eve nt.*;importjavax.swi ng.*;import java.applet.*;importjava.la ng.Stri ng.*;import java.lang.*;import java.io.*;publicclassBlockexte ndsJPa nelimpleme ntsActionListener,KeyListener/应该是继承JP
2、anelstaticButt onbut =new Butt on 6;staticButt onn oStop :=new Button(取消暂停);staticLabelscoreLab=new Label( 分数:);staticLabelin foLab:=new Label( 提示:);staticLabelspeedLab=new Label( 级数:);staticLabelscoreTex=new Label( 0);staticLabelin foTex:=new Label();staticLabelspeedTex=new Label( 1);staticJFramejf
3、 = new JFrame();staticMyTimertimer ;staticImageIc onicon= new ImageIc on(resource/Block.jpg);staticJMen uBarmb =new JMe nuBar();staticJMe numenuO =new JMenu(游戏);staticJMe numenu1 =new JMenu(帮助”);staticJMenultemmi0 :=new JMenultem(新游戏”);staticJMen ultemmi1 :=new JMenultem(退出”);staticJMe nultemmi1_C)-
4、 new JMenultem(关于”);staticJDialogdlg_15staticJTextAreadlg_1_text= new JTextArea();staticint startSig n:=0;/游戏开始标志0 未开始1 开始2暂停static String butLab = 开 始 游 戏,”重 新 开 始,”降 低 级 数,”提高级数,”游戏暂停,”退出游戏;staticintgame_body =newint1910;staticintgame_sig n_x=newint4;/用于记录4个方格的水平位置staticintgame_sig n_y=newint4;/用于
5、记录4个方格的垂直位置staticboolea ndow nSig n:false;/是否落下staticstaticstaticintintintblockNumber gameScore = speedMark =0;1;1;/砖块的编号/游戏分数public static void main( Stri ng args) Block myBlock =new Block();mb.add( menuO );mb.add( menu1 );menu。.add( mi0 );menu。.add( mil );menu1 .add( mi1_0 );jf .setJMenuBar( mb);m
6、yBlock.i nit();jf .add(myBlock);jf .setSize(565,501);jf .setResizable( false );jf .setTitle( 俄罗斯方块”);jf .setIconlmage( icon .getlmage();jf .setLocation(200,100);jf .show();timer = new MyTimer(myBlock);/ 启动线程timer .setDaemon( true );timer .start();fimar0III I lol .OUopUl ,public void in it()setLayout
7、(n ull );for (int i = 0;i 6;i+)but i = new Button(butLab i);add( but i);but i.addActionListener(this );but i.addKeyListener(this );but i.setBounds(360,(240 + 30 * i),160,25);add(scoreLabadd(scoreTexadd(speedLabadd(speedTexadd(in foLabadd(in foTexadd(scoreLab);););););););scoreLab.setBou nds(320,15,3
8、0,20);scoreTex .setBou nds(360,15,160,20);scoreTex .setBackgro un d(Color.white );speedLab .setBou nds(320,45,30,20);speedTex .setBou nds(360,45,160,20);speedTex .setBackgro un d(Color.white );but 1.setEnabled(false );but 4.setEnabled(false );in foLab.setBou nds(320,75,30,20);in foTex.setBou nds(360
9、,75,160,20);in foTex.setBackgro un d(Color.whiteno Stop.setBou nds(360,360,160,25);no Stop.addActi on Liste ner(this );no Stop.addKeyListe ner(this );mi0 .addActionListener(this );mi1 .addActi on Liste ner(this );mi1_0.addAct ion Liste ner(this );nu m_csh_game();ran d_block();欢迎下载13actio nPerformed(
10、Actio nEve nt e)mi0 ) /重新开始游戏public voidif (e.getSource()=startSig n = 1; in foTex.setText(but 0.setEnabled( but 1.setEnabled( but 4.setEnabled( timer .resume();if (e.getSource()=startSig n = 0; gameScore = 0; timer .suspe nd();nu m_csh_restart(); repa in t();ran d_block(); scoreTex .setText( in foT
11、ex.setText(but 0.setEnabled( but 1.setEnabled(but 0)/开始游戏游戏已经开始!);false );true );true );but 1|e.getSource()0);新游戏!); true ); false );false );but 2)/降低级数降低级数!);but 4.setEnabled( if (e.getSource()=in foTex .setText( speedMark -;if ( speedMark = 9) speedMark = 9;in foTex.setText(speedTex .setText(if (e
12、.getSource()=this .add( noStop );this .remove( but 4 in foTex.setText(已经是最低级数!); speedMark +);but 3)/提高级数提高级数!);已经是最高级数!); speedMark +);but 4)/游戏暂停);游戏暂停!);timer .susp en d();if (e.getSource() =noStop ) / 取消暂停this .remove( noStop );this .add( but 4);infoTex .setText(继续游戏!);timer .resumeO;if (e.getSo
13、urce()= jf .dispose();if (e.getSource()=but 5|e.getSource()=mi1_0 ) II退出游戏mi1 )II退出游戏dlg_1 = new JDialog( try Filel nputStreamjf,” 关于”);ionewFileI nputStream( byte a= io.read(a);resource/gua nyu .txt new byte io.available(););/得到路径io.close();String str =new Strin g(a);dlg_1_text .setText(str);catch
14、(Excepti on g)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();public void rand_block()/ 随机产生砖块int num;num =(int )(Math.random () * 6) + 1;/产生06之间的随机数blockNumber = num;switch r(blo
15、ckNumber)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 ;public void change_body(int bloc
16、kNumber) / 改变砖块状态di ngwei();if (blockNumber = 1&downSign= false ) / 变换长条 2种情况/说明if ( game_sign_y0 = game_sign_y 1& game_sign_y3 =2& game_body game_sign_y num_csh_game();game_body game_sign_y3 + 2game_sign_x3 - 2 != 2)0 - 1game_sign_x0 + 1 = 1;game_body game_sign_y1 game_sign_x 1 =1;game_body game_si
17、gn_y2 + 1game_sign_x2 - 1 = 1;game_body game_sign_y3 + 2game_sign_x3 - 2 = 1;infoTex .setText( 游戏进行中 ! );repaint();+ 1 game_sign_x 0-1!=game_sign_x 2& game_sign_y 2 =1)if ( game_body game_sign_y 02& game_body game_sign_y 2 - 1= game_sign_y 3& game_sign_x 0 =+ 1 game_sign_x 0 - 1 !=game_sign_x 2 + 1
18、!= 2& game_body1& game_sign_x 3 = 7) / 说明长条是竖着的 2& game_body game_sign_y num_csh_game();3 - 2game_sign_x3 + 2 != 2)game_body game_sign_y0 + 1game_sign_x0- 1 = 1;game_body game_sign_y1 game_sign_x 1=1;game_body game_sign_y2 - 1game_sign_x2+ 1 = 1;game_body game_sign_y3 - 2game_sign_x3+ 2 = 1;infoTex
19、.setText( 游戏进行中 ! );if ( game_body game_sign_y 0repaint();if (blockNumber = 3& downSign = false ) / 变换转弯 1有 4种情况if ( game_sign_x 0game_sign_x 1& game_sign_x 0 game_sign_y 3 - 2game_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 =
20、1;game_body game_sign_y 2 - 1game_sign_x 2 + 1 = 1;game_body game_sign_y 3 - 2game_sign_x 3 = 1;infoTex .setText( 游戏进行中 ! );repaint();if ( game_sign_y 1 = game_sign_y 3& game_sign_xgame_sign_y 2& game_sign_y 20 = game_sign_x 3& game_sign_y117)if ( game_body game_sign_y 0game_sign_x 022& game_body ga
21、me_sign_y 1+ 1 game_sign_x 1+ 1=!=!=2& game_body game_sign_y3 - 1 game_sign_x 3 - 1 != 2)num_csh_game();game_body game_sign_y game_body game_sign_y game_body game_sign_y game_body game_sign_y0 game_sign_x 0 - 2 = 1;1 + 1 game_sign_x 1 + 1 = 1;2 game_sign_x 2 = 1;3 - 1 game_sign_x 3 - 1 = 1;infoTex .
22、setText( 游戏进行中 ! );repaint();if ( game_sign_x 1game_sign_x 2& game_sign_x 1game_sign_x 3& game_sign_y 08)if ( game_body game_sign_y 02& game_body game_sign_y 12& game_body game_sign_y= game_sign_y 1& game_sign_x 3+ 2 game_sign_x 0+ 1 game_sign_x 1 - 1=!=!=3 - 1 game_sign_x 3 + 1 != 2) num_csh_game()
23、;game_body game_sign_y0 + 2game_sign_x0 =1game_body game_sign_y1 +1game_sign_x1 -1game_body game_sign_y2game_sign_x 2 =1;game_body game_sign_y3 -1game_sign_x3 +1= 1;= 1;infoTex .setText( 游戏进行中 ! );repaint();if ( game_sign_y 0game_sign_y 1& game_sign_y 1game_sign_x 3)game_sign_y 2& game_sign_x 0 =if
24、( game_body game_sign_y 02& game_body game_sign_y 2 - 1 + 1 game_sign_x 0 + 1 != game_sign_x 2 - 1 != 2& game_bodygame_body game_sign_y game_body game_sign_y game_body game_sign_y game_body game_sign_y game_sign_y 3 game_sign_x 3 + 2 != 2) num_csh_game();0 + 1game_sign_x 0 + 1 = 1;1 game_sign_x 1 =
25、1;2 - 1 game_sign_x 2 - 1 = 1;3 game_sign_x 3 + 2 = 1;infoTex .setText( 游戏进行中 ! );repaint();if (blockNumber = 4&downSign= false ) / 变换转弯 2有 4种情况if ( game_sign_x 0game_sign_x 1& game_sign_x 0game_sign_x 3& game_sign_y7)1 = game_sign_y 2& game_sign_x3 =if ( game_body game_sign_y 0 2& game_body game_si
26、gn_y 2 2& game_body game_sign_ygame_sign_x 01 game_sign_x 22!=1!=3 - 2 game_sign_x 3 != 2)num_csh_game();game_body game_sign_y 0game_body game_sign_y 1game_sign_x 0 - 2 = 1;game_sign_x 1 = 1;game_body game_sign_y 2 - 1 game_body game_sign_y 3 - 2game_sign_x game_sign_x2 - 1 = 1;3 = 1;infoTex .setTex
27、t( 游戏进行中 ! );repaint();if ( game_sign_y 0game_sign_y 1& game_sign_y 0game_sign_y 2& game_sign_x16)1 = game_sign_x 3& game_sign_y0 = 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_y3 - 1 game_sign_x 3 + 1 != 2)num_csh_gam
28、e();game_body game_sign_y0 + 1 game_sign_x0 - 1game_body game_sign_y1 game_sign_x 1 -2 = 1;game_body game_sign_y2 game_sign_x 2= 1;game_body game_sign_y3 - 1game_sign_x3 + 1infoTex .setText( 游戏进行中 ! );repaint();= 1;= 1;if ( game_sign_y 1game_sign_y 2& game_sign_y 2game_sign_y 3& game_sign_x0 = game_
29、sign_x 1& game_sign_y0 = 2)game_body game_sign_y0 + 1game_sign_x0 +1game_body game_sign_y1 game_sign_x 1 =1;game_body game_sign_y2 - 1game_sign_x2 -1game_body game_sign_y3 - 2game_sign_x3 =1infoTex .setText( 游戏进行中 ! );= 1;= 1;repaint();if ( game_body game_sign_y 0 game_sign_x 0 - 2 !=2& game_body ga
30、me_sign_y 2 - 1 game_sign_x 2 -1 != 2& game_body game_sign_ygame_sign_x 3 + 1 != 2)3 - 1num_csh_game();game_body game_sign_y0game_body game_sign_y1game_body game_sign_y2 - 1game_body game_sign_y3 - 1infoTex .setText( 游戏进行中 !);IIgame_sign_x game_sign_xrepaint();0 - 2 = 1;1 = 1; game_sign_x game_sign_
31、x2 - 1 = 1;3 + 1 = 1;if ( game_sign_y 0 =game_sign_y1& game_sign_y3 = 17)if ( game_body game_sign_y 0 game_sign_x 0 2& game_body game_sign_y 1 + 1 game_sign_x 2& game_body game_sign_y121!=!=3 + 1 game_sign_x 3 - 1 != 2) num_csh_game();if (blockNumber = 7&if ( game_sign_x 0 =downSigngame_sign_xfalse
32、) / 变换两层砖块 2 的2种情况1& game_sign_x0 = 16)if ( game_body game_sign_y 0 game_sign_x 0 2& game_body game_sign_y 1 - 1 game_sign_x 2& game_body game_sign_y2+ 1!=!=game_body game_sign_y0game_sign_x 0 +2 = 1;game_body game_sign_y1 +1 game_sign_x1 + 1game_body game_sign_y2game_sign_x 2 =1;game_body game_sign
33、_y3 +1 game_sign_x3 - 1infoTex .setText( 游戏进行中! );= 1;= 1;repaint();3 - 1 game_sign_x 3 - 1 != 2) num_csh_game();game_body game_sign_y0game_body game_sign_y1 - 1game_body game_sign_y2game_body game_sign_y3 - 1infoTex .setText( 游戏进行中 !repaint(); );game_sign_x 0 + 2 = 1; game_sign_x 1 + 1 = 1;if ( gam
34、e_sign_y 0 = game_sign_yif ( game_body game_sign_y 01&+ 12& game_body game_sign_y 1 game_sign_x2& game_body game_sign_ygame_sign_y 2 = 17)game_sign_x 01 -21!=!=2 + 1 game_sign_x 2 + 1 != 2) game_body game_sign_y0 + 1 game_sign_x0 - 1game_body game_sign_y1game_sign_x 1 -2 =1;game_body game_sign_y2 +1
35、 game_sign_x2+ 1game_body game_sign_y3game_sign_x 3= 1;infoTex .setText( 游戏进行中! );num_csh_game();repaint();= 1;= 1;public void num_csh_game() / 数组清零 for ( int i = 0;i 19;i+)for ( int j = 0;j 10;j+) if ( game_body ij = 2)game_body ij = 2;elsegame_body ij = 0;game_sign_x 2 = 1; game_sign_x 3 - 1 = 1;p
36、ublic void num_csh_restart() / 重新开始时数组清零for ( int i = 0;i 19;i+)for ( int j = 0;j 10;j+)game_body ij = 0;publicvoid keyTyped(KeyEvent e)publicvoid keyPressed(KeyEvent e)VK_DOWN&startSign= 1)/ 处理下键VK_LEFT &startSign= 1)/ 处理左键VK_RIGHT &startSign= 1)/ 处理右键VK_UP&startSign = 1) /处理上键转换if (e.getKeyCode()
37、= KeyEvent.this .down();if (e.getKeyCode() = KeyEvent.this .left();if (e.getKeyCode() = KeyEvent.this .right();if (e.getKeyCode() = KeyEvent.this .change_body( blockNumber );if ( startSign = 0)infoTex .setText( 游戏未开始或已结束 ! ); publicvoid keyReleased(KeyEvent e)publicvoid paint(Graphics g)g.setColor(Color. bl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 8815-2026电线电缆用软聚氯乙烯塑料
- 2027年吉林省白山市高三(最后冲刺)物理试卷(含答案解析)
- 广西壮族自治区百色市2027年高三第三次模拟考试物理试卷(含答案解析)
- 工厂物料仓管员2026年二季度物料出入库工作总结
- 交通运输行业夏季安全培训课件
- 2026年秋季大学开学第一课 劳动教育 实践出真知
- 2026年秋季物联网工程专业开学第一课 行业前沿与趋势洞察课件
- 2026年北师大版小学三年级英语上册Lesson2《BoyandGirl》说课教案
- 2026年办公哲学思考 极简文具生活方式
- 健康教育三年级下
- 半导体制造研发合作协议
- 新能源汽车电气系统检修-配套课件
- 《齐文化简单介绍》课件
- 出纳常用表格模板格大全
- 老年失能全周期综合康复管理模式专家共识
- 苏教版四年级上册数学第四单元《统计表和条形统计图(一)》测试卷(含答案解析)
- JJG 949-2011经纬仪检定装置检定规程
- 市技能大师工作室建设方案
- 《电力电容器》课件
- 办公设备资产评估报告
- 档案密集架采购投标方案(技术标)
评论
0/150
提交评论