小游戏俄罗斯方块代码(JAVA).doc

上传人:飞****9 文档编号:134061005 上传时间:2020-06-02 格式:DOC 页数:20 大小:92KB
返回 下载 相关 举报
小游戏俄罗斯方块代码(JAVA).doc_第1页
第1页 / 共20页
小游戏俄罗斯方块代码(JAVA).doc_第2页
第2页 / 共20页
小游戏俄罗斯方块代码(JAVA).doc_第3页
第3页 / 共20页
小游戏俄罗斯方块代码(JAVA).doc_第4页
第4页 / 共20页
小游戏俄罗斯方块代码(JAVA).doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

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

1、东西绝对不多说,直接看!看了拷贝就懂了!,直接可以拷贝下面的东西,然后记得把那个BLOCK的名字改成你自己的类名,这个很关键哦,不然是错的可别怪我,呵呵import java.awt.*;import java.awt.event.*;import javax.swing.*; import java.applet.*;import java.lang.String.*;import java.lang.*;import java.io.*;public class Block extends JPanel implements ActionListener,KeyListener/应该是继承

2、JPanelstatic Button but = new Button6;static Button noStop = new Button(取 消 暂 停);static Label scoreLab = new Label(分数:);static Label infoLab = new Label(提示:);static Label speedLab = new Label(级数:);static Label scoreTex = new Label(0);static Label infoTex = new Label( );static Label speedTex = new La

3、bel(1);static JFrame jf = new JFrame();static MyTimer timer; static ImageIcon icon=new ImageIcon(resource/Block.jpg);static JMenuBar mb = new JMenuBar();static JMenu menu0 = new JMenu(游戏 );static JMenu menu1 = new JMenu(帮助 );static JMenuItem mi0 = new JMenuItem(新 游 戏);static JMenuItem mi1 = new JMen

4、uItem(退出);static JMenuItem mi1_0 = new JMenuItem(关于); static JDialog dlg_1;static JTextArea dlg_1_text = new JTextArea();static int startSign = 0;/游戏开始标志 0 未开始 1 开始 2 暂停static String butLab = 开 始 游 戏,重 新 开 始,降 低 级 数,提 高 级 数,游 戏 暂 停,退 出 游 戏;static int game_body = new int1910;static int game_sign_x =

5、new int4;/用于记录4个方格的水平位置static int game_sign_y = new int4;/用于记录4个方格的垂直位置static boolean downSign = false;/是否落下static int blockNumber = 1;/砖块的编号static int gameScore = 0;/游戏分数static int speedMark = 1;public static void main(String args) Block myBlock = new Block();mb.add(menu0);mb.add(menu1);menu0.add(m

6、i0);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 = new MyTimer(myBlock); /启动线程 timer.setDaemon(true); timer.start(); timer.su

7、spend();public void init() setLayout(null); for(int i = 0;i 6;i+) buti = new Button(butLabi); add(buti); buti.addActionListener(this); buti.addKeyListener(this); buti.setBounds(360,(240 + 30 * i),160,25); add(scoreLab); add(scoreTex); add(speedLab); add(speedTex); add(infoLab); add(infoTex); add(sco

8、reLab); 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);but1.setEnabled(false);but4.setEnabled(false);infoLab.setBounds(320,75,30,20);infoTex

9、.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(); public void actionPerformed(Acti

10、onEvent e) if(e.getSource() = but0)/开始游戏 startSign = 1; infoTex.setText(游戏已经开始!); but0.setEnabled(false); but1.setEnabled(true); but4.setEnabled(true); timer.resume(); if(e.getSource() = but1|e.getSource() = mi0)/重新开始游戏 startSign = 0; gameScore = 0; timer.suspend(); num_csh_restart(); repaint(); ran

11、d_block(); scoreTex.setText(0); infoTex.setText(新游戏!); but0.setEnabled(true); but1.setEnabled(false); but4.setEnabled(false); if(e.getSource() = but2)/降低级数 infoTex.setText(降低级数!); speedMark-; if(speedMark = 9) speedMark = 9; infoTex.setText(已经是最高级数!); speedTex.setText(speedMark + ); if(e.getSource()

12、 = but4)/游戏暂停 this.add(noStop); this.remove(but4); infoTex.setText(游戏暂停!); timer.suspend(); if(e.getSource() = noStop)/取消暂停 this.remove(noStop); this.add(but4); infoTex.setText(继续游戏!); timer.resume(); if(e.getSource() = but5|e.getSource() = mi1)/退出游戏 jf.dispose(); if(e.getSource() = mi1_0)/退出游戏 dlg_

13、1 = new JDialog(jf,关 于); try FileInputStream io = new FileInputStream(resource/guanyu.txt);/得到路径 byte a = new byteio.available(); io.read(a); io.close(); String str = new String(a); dlg_1_text.setText(str); catch(Exception 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之间的随

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 幼儿/小学教育 > 幼儿教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号