《俄罗斯方块完整源代码》由会员分享,可在线阅读,更多相关《俄罗斯方块完整源代码(53页珍藏版)》请在金锄头文库上搜索。
1、staticstaticstaticLabelscoreLab = new Label(分数:);staticLabelinfoLab = new Label(提示:);staticLabelspeedLab = new Label(级数:);staticLabelscoreTex =new Label(0);staticLabelinfoTex = new Label( );staticLabelspeedTex =new Label(1);/不多说,直接可以拷贝下面的东西,就可以运行。package day04;import java.awt.*;import java.awt.event
2、.*;import javax.swing.*;import java.apple t.*;import java.lang.S tring .*;import java.lang .*;import java.io.*;public class ERSBlock extends JPanel implementsActio nLis tener,KeyLis tener/应该是继承J PanelButton but = new Button6;Button noStop = new Button(取消暂停);static JFrame jf = new JFrame();static MyT
3、imer timer;static ImageIconicon=newImageIcon(resource/Block.jpg);static JMenuBar mb =new JMenuBar();static JMenu menuO = new JMenu (游戏 );static JMenu menul = new JMenu (帮助 );static JMenultem miO = new JMenultem(新 游 戏); static JMenultem mil = new JMenultem(退出);static JMenultem mi1_O = new JMenultem(关
4、于);static JDialog dlg_1;static JTextArea dlg_1_text =new JTextArea();static int start Sign二0;/游戏开始标志0未开始1开 始 2 暂停static StringbutLab = 开始 游 戏,重 新 开 始 ,降 低 级 数,提 高 级 数,游 戏 暂 停,退 出 游 戏;staticintgame_bod = newint1910;static int game_sign_ = new int 4;/用于记录 4个 方格的水平位置static int game_sign_ = new int 4;/用
5、于记录 4个 方格的垂直位置static boolean downSign = false;/是否落下static int blockNumber = 1;/砖块的编号static int gameScore = 0;/游戏分数static int speedMark = 1;public static void main(String args)ERSBlock myBlock = new ERSBlock();mb.add(menu0);mb.add(menu1);menu0.add(mi0);menu0.add(mi1);menu1.add(mi1_0);jf.setJMenuBar(m
6、b);myBlock.init();jf.add(myBlock);jf.setSize(565,501); jf.setResizable(false);jf.se tTi tle(俄罗斯方块);jf. setIconImage (icon. getImage () ;jf.setLocation(200,100);jf.show();timer = new MyTimer(myBlock); /启动线程timer.setDaemon(true);timer.start();ti mer.suspend();public void init()setLayout(null);for(int
7、i = 0;i = 9)speedMark = 9;infoTex, set Tex t(已经是最高级数!);speedTex set Tex t( speedMark+ );if (e ge tSource() = bu t4)/游戏暂停 this.add(noStop);this.remove(but4);infoTex, set Tex t(游戏暂停!);ti mer.suspend();if (e.ge tSource() = noS to p) / 取消暂停 this.remove(noStop);this.add(but4);infoTex, set Tex t(继续游戏!);ti
8、 mer.resume();if(e.getSource() = but5|e.getSource() = mi1)/ 退出游戏jf.dispose();if(e.ge tSource() = mil_0)/退出游戏dlg_1 = new JDialog(jf, 关 于);tryFileInputStreamio=newFilelnp utSt ream(resource/guany u.txt);/得到路径 byte a = newbyteio.available(); io.read(a); io.close();String str = new String(a); dlg_1_tex.
9、setText(str); catch(Exception g)d l g_ 1 _tex . s e t Ed i t ab l e ( false) ; dlg_1.add(dlg_1_tex);dlg_1.pack();dlg_1.setResizable(false);dlg_1.setSize(200, 120);dlg_1.setLocation(400, 240); dlg_Lshow();public void rand_block() /随机产生砖块int num;num = (int)(Math.random() * 6) + 1;/产生06之间的随机数blockNumber = num;switch (blockNumbe )case 1: block1(); blockNumber = 1; break ;case 2: block2(); blockNumber = 2; break ;case 3: block3(); blockNumber = 3; break ;case 4: block4(); blockNumber = 4; break ;case 5: bloc