小游戏俄罗斯方块代码

上传人:工**** 文档编号:470477937 上传时间:2023-03-03 格式:DOCX 页数:24 大小:41.11KB
返回 下载 相关 举报
小游戏俄罗斯方块代码_第1页
第1页 / 共24页
小游戏俄罗斯方块代码_第2页
第2页 / 共24页
小游戏俄罗斯方块代码_第3页
第3页 / 共24页
小游戏俄罗斯方块代码_第4页
第4页 / 共24页
小游戏俄罗斯方块代码_第5页
第5页 / 共24页
点击查看更多>>
资源描述

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

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,

2、KeyListener/应该是继承JPanel static 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( ); stati

3、c Label speedTex = new Label(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(新 游 戏); sta

4、tic JMenuItem mi1 = new JMenuItem(退出); 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 in

5、t1910; static int game_sign_x = 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

6、.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 = new MyTimer(myBlock); /启动线程 time

7、r.setDaemon(true); timer.start; timer.suspend; 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)

8、; 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); but1.setEnabled(false); but4.setEnabled(fal

9、se); 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_

10、game; rand_block; public void actionPerformed(ActionEvent 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.su

11、spend; num_csh_restart; repaint; rand_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

12、(speedMark + ); if(e.getSource = 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 =

13、mi1_0)/退出游戏 dlg_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之间的随机数 blockNumber = num; switch(blockNumber) case 1: block1; blockNumber = 1; break; case 2: block2; bloc

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

当前位置:首页 > 建筑/环境 > 施工组织

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