小游戏俄罗斯方块代码.docx

上传人:牧羊曲112 文档编号:3475117 上传时间:2023-03-13 格式:DOCX 页数:24 大小:41.11KB
返回 下载 相关 举报
小游戏俄罗斯方块代码.docx_第1页
第1页 / 共24页
小游戏俄罗斯方块代码.docx_第2页
第2页 / 共24页
小游戏俄罗斯方块代码.docx_第3页
第3页 / 共24页
小游戏俄罗斯方块代码.docx_第4页
第4页 / 共24页
小游戏俄罗斯方块代码.docx_第5页
第5页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《小游戏俄罗斯方块代码.docx》由会员分享,可在线阅读,更多相关《小游戏俄罗斯方块代码.docx(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.pa

14、ck; 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; blockNumber = 2; break;

15、case 3: block3; blockNumber = 3; break; case 4: block4; blockNumber = 4; break; case 5: block5; blockNumber = 5; break; case 6: block6; blockNumber = 6; break; case 7: block7; blockNumber = 7; break; public void change_body(int blockNumber)/改变砖块状态 dingwei; if(blockNumber = 1&downSign = false)/变换长条2种

16、情况 if(game_sign_y0 = game_sign_y1&game_sign_y3 = 16)/说明长条是横着的 if(game_bodygame_sign_y0 - 1game_sign_x0 + 1 != 2&game_bodygame_sign_y3 + 2game_sign_x3 - 2 != 2) num_csh_game; game_bodygame_sign_y0 - 1game_sign_x0 + 1 = 1; game_bodygame_sign_y1game_sign_x1 = 1; game_bodygame_sign_y2 + 1game_sign_x2 -

17、1 = 1; game_bodygame_sign_y3 + 2game_sign_x3 - 2 = 1; infoTex.setText(游戏进行中!); repaint; if(game_sign_x0 = game_sign_x1&game_sign_x0 1&game_sign_x3 = 1) if(game_bodygame_sign_y0 + 1game_sign_x0 - 1 != 2&game_bodygame_sign_y2 - 1game_sign_x2 + 1 != 2&game_body game_sign_y3 - 2game_sign_x3 != 2) num_cs

18、h_game; game_bodygame_sign_y0 + 1game_sign_x0 - 1 = 1; game_bodygame_sign_y1game_sign_x1 = 1; = != game_bodygame_sign_y2 - 1game_sign_x2 + 1 = 1; game_bodygame_sign_y3 - 2game_sign_x3 = 1; infoTex.setText(游戏进行中!); repaint; if(game_sign_y1 = game_sign_y2&game_sign_y2 = game_sign_y3&game_sign_x0 = gam

19、e_sign_x3&game_sign_y1 = 17) if(game_bodygame_sign_y0game_sign_x0 - 2 != 2&game_bodygame_sign_y1 + 1game_sign_x1 + 1 != 2&game_bodygame_sign_y 3 - 1game_sign_x3 - 1 != 2) num_csh_game; game_bodygame_sign_y0game_sign_x0 - 2 = 1; game_bodygame_sign_y1 + 1game_sign_x1 + 1 = 1; game_bodygame_sign_y2game

20、_sign_x2 = 1; game_bodygame_sign_y3 - 1game_sign_x3 - 1 = 1; infoTex.setText(游戏进行中!); repaint; if(game_sign_x1 = game_sign_x2&game_sign_x1 = game_sign_x3&game_sign_y0 = game_sign_y1&game_sign_x3 = 8) if(game_bodygame_sign_y0 + 2game_sign_x0 != 2&game_bodygame_sign_y1 + 1game_sign_x1 - 1 != 2&game_bo

21、dygame_sign_y 3 - 1game_sign_x3 + 1 != 2) num_csh_game; game_bodygame_sign_y0 + 2game_sign_x0 = 1; game_bodygame_sign_y1 + 1game_sign_x1 - 1 = 1; game_bodygame_sign_y2game_sign_x2 = 1; game_bodygame_sign_y3 - 1game_sign_x3 + 1 = 1; infoTex.setText(游戏进行中!); repaint; if(game_sign_y0 = game_sign_y1&gam

22、e_sign_y1 = game_sign_y2&game_sign_x0 = game_sign_x3) if(game_bodygame_sign_y0 + 1game_sign_x0 + 1 != 2&game_bodygame_sign_y2 - 1game_sign_x2 - 1 != 2&game_body game_sign_y3game_sign_x3 + 2 != 2) num_csh_game; game_bodygame_sign_y0 + 1game_sign_x0 + 1 = 1; game_bodygame_sign_y1game_sign_x1 = 1; game

23、_bodygame_sign_y2 - 1game_sign_x2 - 1 = 1; game_bodygame_sign_y3game_sign_x3 + 2 = 1; infoTex.setText(游戏进行中!); repaint; if(blockNumber = 4&downSign = false)/变换转弯2有4种情况 if(game_sign_x0 = game_sign_x1&game_sign_x0 = game_sign_x3&game_sign_y1 = game_sign_y2&game_sign_x3 = 2) if(game_bodygame_sign_y0gam

24、e_sign_x0 - 2 != 2&game_bodygame_sign_y2 - 1game_sign_x2 - 1 != 2&game_bodygame_sign_y 3 - 2game_sign_x3 != 2) num_csh_game; game_bodygame_sign_y0game_sign_x0 - 2 = 1; game_bodygame_sign_y1game_sign_x1 = 1; game_bodygame_sign_y2 - 1game_sign_x2 - 1 = 1; game_bodygame_sign_y3 - 2game_sign_x3 = 1; inf

25、oTex.setText(游戏进行中!); repaint; if(game_sign_y0 = game_sign_y1&game_sign_y0 = game_sign_y2&game_sign_x1 = game_sign_x3&game_sign_y0 = 2) if(game_bodygame_sign_y0 + 1game_sign_x0 - 1 != 2&game_bodygame_sign_y1game_sign_x1 - 2 != 2&game_bodygame_sign_y 3 - 1game_sign_x3 + 1 != 2) num_csh_game; game_bod

26、ygame_sign_y0 + 1game_sign_x0 - 1 = 1; game_bodygame_sign_y1game_sign_x1 - 2 = 1; game_bodygame_sign_y2game_sign_x2 = 1; game_bodygame_sign_y3 - 1game_sign_x3 + 1 = 1; infoTex.setText(游戏进行中!); repaint; if(game_sign_y1 = game_sign_y2&game_sign_y2 = game_sign_y3&game_sign_x0 = game_sign_x1&game_sign_y

27、0 = 2) if(game_bodygame_sign_y0game_sign_x0 - 2 2&game_bodygame_sign_y2 - 1game_sign_x2 -1 2&game_bodygame_sign_y 3 - 1game_sign_x3 + 1 != 2) num_csh_game; game_bodygame_sign_y0game_sign_x0 - 2 = 1; game_bodygame_sign_y1game_sign_x1 = 1; game_bodygame_sign_y2 - 1game_sign_x2 - 1 = 1; game_bodygame_s

28、ign_y3 - 1game_sign_x3 + 1 = 1; infoTex.setText(游戏进行中!); repaint; if(game_sign_y0 = game_sign_y1&game_sign_y3 = 17) if(game_bodygame_sign_y0game_sign_x0 + 2 2&game_bodygame_sign_y1 + 1game_sign_x1 + 1 2&game_bodygame_sign_y 3 + 1game_sign_x3 - 1 != 2) num_csh_game; game_bodygame_sign_y0game_sign_x0 + 2 = 1; game_bodygame_sign_y1 + 1game_sign_x1 + 1 = 1; game_bodygame_sign_y2game_sign_x2 = 1; game_bodygame_sign_y3 + 1game_sign_x3 - 1 = 1; infoTex.setText(游戏进行中!); repaint; if(blockNumber = 7&downSign = false)/变换两层砖块2的2种情况

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号