本文实例为大家分享了java实现俄罗斯方块小游戏的具体代码,供大家参考,具体内容如下
1、 在二维平面里面用各种随机产生的方块堆积木,每满一行消去一行,当达到顶部时,游戏结束。
2、 通过方向键来控制方块转动,左移,右移和直落。
3、 方块下落统一设置蓝色,接触底部变粉色。
4、 计算分数,分数是由方块的类型决定的,每堆积一个方块就把分数累加到总分中。
5、 游戏有开始、重新开始、降低提高级数(速度)、暂停、退出
这个是最基础的方块素材
package 俄罗斯方块;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//应该是继承jpanel{ static button but[] = new button[6]; 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 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("新 游 戏")312; static 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 int[19][10]; static int game_sign_x[] = new int[4];//用于记录4个方格的水平位置 static int game_sign_y[] = new int[4];//用于记录4个方格的垂直位置 static boolean downsign = fal;//是否落下 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(mi0); menu0.add(mi1); menu1.add(mi1_0); jf.tjmenubar(mb); myblock.init(); jf.add(myblock); jf.tsize(565,501); jf.tresizable(fal); jf.ttitle("俄罗斯方块"); jf.ticonimage(icon.getimage()); jf.tlocation(200,100); jf.show(); timer = new mytimer(myblock); //启动线程 timer.tdaemon(true); timer.start(); timer.suspend(); } public void init() { tlayout(null); 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].tbounds(360,(240 + 30 * i),160,25); } add(scorelab); add(scoretex); add(speedlab); add(speedtex); add(infolab); add(infotex); add(scorelab); scorelab.tbounds(320,15,30,20); scoretex.tbounds(360,15,160,20); scoretex.tbackground(color.white); speedlab.tbounds(320,45,30,20); speedtex.tbounds(360,45,160,20); speedtex.tbackground(color.white); but[1].tenabled(fal); but[4].tenabled(fal); infolab.tbounds(320,75,30,20); infotex.tbounds(360,75,160,20); infotex.tbackground(color.white); nostop.tbounds(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(actionevent e) { if(e.getsource() == but[0])//开始游戏 { startsign = 1; infotex.ttext("游戏已经开始!"); but[0].tenabled(fal); but[1].tenabled(true); but[4].tenabled(true); timer.resume(); } if(e.getsource() == but[1]||e.getsource() == mi0)//重新开始游戏 { startsign = 0; gamescore = 0; timer.suspend(); num_csh_restart(); repaint(); rand_block(); scoretex.ttext("0"); infotex.ttext("新游戏!"); but[0].tenabled(true); but[1].tenabled(fal); but[4].tenabled(fal); } if(e.getsource() == but[2])//降低级数 { infotex.ttext("降低级数!"); speedmark--; if(speedmark <= 1) { speedmark = 1; infotex.ttext("已经是最低级数!"); } speedtex.ttext(speedmark + ""); } if(e.getsource() == but[3])//提高级数 { infotex.ttext("提高级数!"); speedmark++; if(speedmark >= 9) { speedmark = 9; infotex.ttext("已经是最高级数!"); } speedtex.ttext(speedmark + ""); } if(e.getsource() == but[4])//游戏暂停 { this.add(nostop); this.remove(but[4]); infotex.ttext("游戏暂停!"); timer.suspend(); } if(e.getsource() == nostop)//取消暂停 { this.remove(nostop); this.add(but[4]); infotex.ttext("继续游戏!"); timer.resume(); } if(e.getsource() == but[5]||e.getsource() == mi1)//退出游戏 { jf.dispo(); } if(e.getsource() == mi1_0)//退出游戏 { dlg_1 = new jdialog(jf,"关 于"); try{ fileinputstream io = new fileinputstream("resource/guanyu.txt");//得到路径 byte a[] = new byte[io.available()]; io.read(a); io.clo(); string str = new string(a); dlg_1_text.ttext(str); } catch(exception g){} dlg_1_text.teditable(fal); dlg_1.add(dlg_1_text); dlg_1.pack(); dlg_1.tresizable(fal); dlg_1.tsize(200, 120); dlg_1.tlocation(400, 240); dlg_1.show(); } } public void rand_block()//随机产生砖块 { int num; num = (int)(math.random() * 6) + 1;//产生0~6之间的随机数 blocknumber = num; switch(blocknumber) { ca 1: block1(); blocknumber = 1; break; ca 2: block2(); blocknumber = 2; break; ca 3: block3(); blocknumber = 3; break; ca 4: block4(); blocknumber = 4; break; ca 5: block5(); blocknumber = 5; break; ca 6: block6(); blocknumber = 6; break; ca 7: block7(); blocknumber = 7; break; } } public void change_body(int blocknumber)//改变砖块状态 { dingwei(); if(blocknumber == 1&&downsign == fal)//变换长条2种情况 { if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[3] <= 16)//说明长条是横着的 { if(game_body[game_sign_y[0] - 1][game_sign_x[0] + 1] != 2&&game_body[game_sign_y[3] + 2][game_sign_x[3] - 2] != 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]] = 1; game_body[game_sign_y[2] + 1][game_sign_x[2] - 1] = 1; game_body[game_sign_y[3] + 2][game_sign_x[3] - 2] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] >= 1&&game_sign_x[3] <= 7)//说明长条是竖着的 { if(game_body[game_sign_y[0] + 1][game_sign_x[0]-1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3] + 2] != 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]]=1; game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] = 1; game_body[game_sign_y[3] - 2][game_sign_x[3] + 2] = 1; infotex.ttext("游戏进行中!"); repaint(); } } } if(blocknumber == 3&&downsign == fal)//变换转弯1有4种情况 { if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] == game_sign_x[2]&&game_sign_y[2] == game_sign_y[3]&&game_sign_x[0] >= 1) { if(game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] != 2&&game_body[game_sign_y[3] - 2][game_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]] = 1; game_body[gam爱不单行歌词e_sign_y[2] - 1][game_sign_x[2] + 1] = 1; game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[1] == game_sign_y[2]&&game_sign_y[2] == game_sign_y[3]&&game_sign_x[0] == game_sign_x[3]&&game_sign_y[1] <= 17) { if(game_body[game_sign_y[0]][game_sign_x[0] - 2] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] != 2) { num_csh_game(); game_body[game_sign_y[0]][game_sign_x[0] - 2] = 1; game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_x[1] == game_sign_x[2]&&game_sign_x[1] == game_sign_x[3]&&game_sign_y[0] == game_sign_y[1]&&game_sign_x[3] <= 8) { if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 2) { num_csh_game(); game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1; game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[0] == game_sign_x[3]) { if(game_body[game_sign_y[0] + 1][game_sign_x[0] + 1] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] != 2&&game_body[game_sign_y[3]][game_sign_x[3] + 2] != 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]] = 1; game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1; game_body[game_sign_y[3]][game_sign_x[3] + 2] = 1; infotex.ttext("游戏进行中!"); repaint(); } } } if(blocknumber == 4&&downsign == fal)//变换转弯2有4种情况 { if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] == game_sign_x[3]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[3] <= 7) { if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3]][game_sign_x[3] + 2] != 2) { num_csh_game(); game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1; game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3]][game_sign_x[3] + 2] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[1] == game_sign_y[2]&&game_sign_y[1] == game_sign_y[3]&&game_sign_x[0] == game_sign_x[2]) { if(game_body[game_sign_y[1]][game_sign_x[1] + 2] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3]] != 2) { num_csh_game(); game_body[game_sign_y[0]][game_sign_x[0]] = 1; game_body[game_sign_y[1]][game_sign_x[1] + 2] = 1; game_body[game_sign_y[2] - 1][game_sign_x[2] + 1] = 1; game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_x[0] == game_sign_x[2]&&game_sign_x[0] == game_sign_x[3]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[0] >= 2) { if(game_body[game_sign_y[0]][game_sign_x[0] - 2] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] != 2&&game_body[game_sign_y[3] - 2][game_sign_x[3]] != 2) { num_csh_game(); game_body[game_sign_y[0]][game_sign_x[0] - 2] = 1; game_body[game_sign_y[1]][game_sign_x[1]] = 1; game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1; game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[0] == game_sign_y[2]&&game_sign_x[1] == game_sign_x[3]&&game_sign_y[0] <= 16) { if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] != 2&&game_body[game_sign_y[2]][game_sign_x[2] - 2] != 2) { num_csh_game(); game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1; game_body[game_sign_y[1] + 1][game_sign_x[1] - 1] = 1; game_body[game_sign_y[2]][game_sign_x[2] - 2] = 1; game_body[game_sign_y[3]][game_sign_x[3]] = 1; infotex.ttext("游戏进行中!"); repaint(); } } } if(blocknumber == 5&&downsign == fal)//变换转弯3有4种情况 { if(game_sign_x[0] == game_sign_x[2]&&game_sign_x[2] == game_sign_x[3]&&game_sign_y[0] == game_sign_y[1]&&game_sign_x[1] >= 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_y[3] - 1][game_sign_x[3] + 1] != 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] - 2] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[1] == game_sign_y[2]&&game_sign_y[2] == game_sign_y[3]&&game_sign_x[0] == game_sign_x[1]&&game_sign_y[0] <= 16) { if(game_body[game_sign_y[0] + 2][game_sign_x[0]] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] != 2) { num_csh_game(); game_body[game_sign_y[0] + 2][game_sign_x[0]] = 1; game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[1] == game_sign_x[3]&&game_sign_y[2] == game_sign_y[3]) { if(game_body[game_sign_y[0] + 1][game_sign_x[0] - 1] != 2&&game_body[game_sign_y[2]][game_sign_x[2] + 2] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 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]] = 1; game_body[game_sign_y[2]][game_sign_x[2] + 2] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[1] == game_sign_y[2]&&game_sign_x[2] == game_sign_x[3]) { if(game_body[game_sign_y[0] + 1][game_sign_x[0] + 1] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] != 2&&game_body[game_sign_y[3] - 2][game_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]] = 1; game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1; game_body[game_sign_y[3] - 2][game_sign_x[3]] = 1; infotex.ttext("游戏进行中!"); repaint(); } } } if(blocknumber == 6&&downsign == fal)//变换两层砖块1的2种情况 { if(game_sign_x[0] == game_sign_x[2]&&game_sign_x[0] >= 2) { if(game_body[game_sign_y[0]][game_sign_x[0] - 2] != 2&&game_body[game_sign_y[2] - 1][game_sign_x[2] -1 ] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] != 2) { num_csh_game(); game_body[game_sign_y[0]][game_sign_x[0] - 2] = 1; game_body[game_sign_y[1]][game_sign_x[1]] = 1; game_body[game_sign_y[2] - 1][game_sign_x[2] - 1] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] + 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[3] <= 17) { if(game_body[game_sign_y[0]][game_sign_x[0] + 2] != 2&&game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] + 1][game_sign_x[3] - 1] != 2) { num_csh_game(); game_body[game_sign_y[0]][game_sign_x[0] + 2] = 1; game_body[game_sign_y[1] + 1][game_sign_x[1] + 1] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3] + 1][game_sign_x[3] - 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } } if(blocknumber == 7&&downsign == fal)//变换两层砖块2的2种情况 { if(game_sign_x[0] == game_sign_x[1]&&game_sign_x[0] <= 16) { if(game_body[game_sign_y[0]][game_sign_x[0] + 2] != 2&&game_body[game_sign_y[1] - 1][game_sign_x[1] + 1] != 2&&game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] != 2) { num_csh_game(); game_body[game_sign_y[0]][game_sign_x[0] + 2] = 1; game_body[game_sign_y[1] - 1][game_sign_x[1] + 1] = 1; game_body[game_sign_y[2]][game_sign_x[2]] = 1; game_body[game_sign_y[3] - 1][game_sign_x[3] - 1] = 1; infotex.ttext("游戏进行中!"); repaint(); } } if(game_sign_y[0] == game_sign_y[1]&&game_sign_y[2] <= 17) { 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_y[2] + 1][game_sign_x[2] + 1] != 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] - 2] = 1; game_body[game_sign_y[2] + 1][game_sign_x[2] + 1] = 1; game_body[game_sign_y[3]][game_sign_x[3]] = 1; infotex.ttext("游戏进行中!"); repaint(); } } } } public void num_csh_game()//数组清零 { for(int i = 0;i < 19;i++) { for(int j = 0;j < 10;j++) { if(game_body[i][j] == 2) { game_body[i][j] = 2; } el { game_body[i][j] = 0; } } } } public void num_csh_restart()//重新开始时数组清零 { for(int i = 0;i < 19;i++) { for(int j = 0;j < 10;j++) { game_body[i][j] = 0; } } } public void keytyped(keyevent e){} public void keypresd(keyevent e) { if(e.getkeycode() == keyevent.vk_down&&startsign == 1)//处理下键 { this.down(); } if(e.getkeycode() == keyevent.vk_left&&startsign == 1)//处理左键 { this.left(); } if(e.getkeycode() == keyevent.vk_right&&startsign == 1)//处理右键 { this.right(); } if(e.getkeycode() == keyevent.vk_up&&startsign == 1)//处理上键转换 { this.change_body(blocknumber); } if(startsign == 0) { infotex.ttext("游戏未开始或已结束!"); } } public void keyrelead(keyevent e){} public void paint(graphics g) { g.tcolor(color.black); g.fill3drect(0,0,300,450,true); for(int i = 0;i < 19;i++) { for(int j = 0;j < 10;j++) { if(game_body[i][j] == 1) { g.tcolor(color.blue); g.fill3drect(30*j,30*(i-4),30,30,true); } if(game_body[i][j] == 2) { g.tcolor(color.magenta); g.fill3drect(30*j,30*(i-4),30,30,true); } } } } public void left()//向左移动 { int sign = 0; dingwei(); for(int k = 0;k < 4;k++) { if(game_sign_x[k] == 0||game_body[game_sign_y[k]][game_sign_x[k] - 1] == 2) { sign = 1; } } if(sign == 0&&downsign == fal) { num_csh_game(); for(int k = 0;k < 4;k++) { game_body[game_sign_y[k]][game_sign_x[k] - 1] = 1; } infotex.ttext("向左移动!"); repaint(); } } public void right()//向右移动 { int sign = 0; dingwei(); for(int k = 0;k < 4;k++) { if(game_sign_x[k] == 9||game_body[game_sign_y[k]][game_sign_x[k] + 1] == 2) { sign = 1; } } if(sign == 0&&downsign == fal) { num_csh_game(); for(int k = 0;k < 4;k++) { game_body[game_sign_y[k]][game_sign_x[k] + 1] = 1; } infotex.ttext("向右移动!"); repaint(); } } public void down()//下落 { int sign = 0; dingwei(); for(int k = 0;k < 4;k++) { if(game_sign_y[k] == 18||game_body[game_sign_y[k] + 1][game_sign_x[k]] == 2) { sign = 1; downsign = true; changecolor(); canceldw(); getscore(); if(game_over() == fal) { rand_block(初中教师个人总结); repaint(); } } } if(sign == 0) { num_csh_game(); for(int k = 0;k < 4;k++) { game_body[game_sign_y[k] + 1][game_sign_x[k]] = 1; } infotex.ttext("游戏进行中!"); repaint(); } } public boolean game_over()//判断游戏是否结束 { int sign=0; for(int i = 0;i < 10;i++) { if(game_body[4][i] == 2) { sign = 1; } } if(sign == 1) { infotex.ttext("游戏结束!"); changecolor(); repaint(); startsign = 0; timer.suspend(); return true; } el return fal; } public void getscore()//满行消除方法 { for(int i = 0;i < 19;i++) { int sign = 0; for(int j = 0;j < 10;j++) { if(game_body[i][j] == 2) { sign++; } } if(sign == 10) { gamescore += 100; scoretex.ttext(gamescore+""); infotex.ttext("恭喜得分!"); for(int j = i;j >= 1;j--) { for(int k = 0;k < 10;k++) { game_body[j][k] = game_body[j - 1][k]; } } } } } public void changecolor()//给已经落下的块换色 { downsign = fal; for(int k = 0;k < 4;k++) { game_body[game_sign_y[k]][game_sign_x[k]] = 2; } } public void dingwei()//确定其位置 { int k = 0; canceldw(); for(int i = 0;i < 19;i++) { for(int j = 0;j < 10;j++) { if(game_body[i][j] == 1) { game_sign_x[k] = j; game_sign_y[k] = i; k++; } } } } public void canceldw()//将定位数组初始化 { for(int k = 0;k < 4;k++) { game_sign_x[k] = 0; game_sign_y[k] = 0; } } public void block1()//长条 { game_body[0][4] = 1; game_body[1][4] = 1; game_body[2][4] = 1; game_body[3][4] = 1; } public void block2()//正方形 { game_body[3][4] = 1; game_body[2][4] = 1; game_body[3][5] = 1; game_body[2][5] = 1; } public void block3()//3加1(下) { game_body[1][4] = 1; game_body[2][4] = 1; game_body[3][4] = 1; game_body[3][5] = 1; } public void block4()//3加1(中) { game_body[1][4] = 1; game_body[2][4] = 1; game_body[3][4] = 1; game_body[2][5] = 1; } public void block5()//3加1(上) { game_body[1][4] = 1; game_body[2][4] = 1; game_body[3][4] = 1; game_body[1][5] = 1; } public void block6()//转折1 { game_body[1][5] = 1; game_body[2][5] = 1; game_body[2][4] = 1; game_body[3][4] = 1; } public void block7()//转折2 { game_body[1][4] = 1; game_body[2][4] = 1; game_body[2][5] = 1; game_body[3][5] = 1; }}//定时线程class mytimer 食用明胶extends thread{ block myblock; public mytimer(block myblock) { this.myblock = myblock; } public void run() { while(myblock.startsign == 1) { try{ sleep((10-myblock.speedmark + 1)*100); myblock.down(); } catch(interruptedexception e){} } }}
备注:上键变换方向
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。
本文发布于:2023-04-04 16:02:25,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/c03346c30388503eefe2459ab2f3e4eb.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Java实现俄罗斯方块小游戏源码.doc
本文 PDF 下载地址:Java实现俄罗斯方块小游戏源码.pdf
留言与评论(共有 0 条评论) |