小游戏俄罗斯方块代码(JAVA)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
东西绝对不多说,直接看!看了拷贝就懂了!!,直接可以拷贝下面的东西,然后记得把那个BLOCK 的名字改成你自己的类名,这个很关键哦,不然是错的可别怪我,呵呵~~
import java.awt.*;
import
import javax.swing.*;
import java.applet.*;
import.*;
import ng.*;
import java.io.*;
publicclass 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("新游戏");
static JMenuItem mi1=new JMenuItem("退出");
static JMenuItem mi1_0=new JMenuItem("关于");
static JDialog dlg_1;
static JTextArea dlg_1_text=new JTextArea();
staticint startSign=0;//游戏开始标志0未开始1开始2暂停
static String butLab[]={"开始游戏","重新开始","降低级数","提高级数","游戏暂停","退出游戏"}; staticint game_body[][]=newint[19][10];
staticint game_sign_x[]=newint[4];//用于记录4个方格的水平位置
staticint game_sign_y[]=newint[4];//用于记录4个方格的垂直位置
staticboolean downSign=false;//是否落下
staticint blockNumber=1;//砖块的编号
staticint gameScore=0;//游戏分数
staticint speedMark=1;
publicstaticvoid main(Stringargs[])
{
BlockmyBlock=new Block();
mb.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);//启动线程timer.setDaemon(true);
timer.start();
timer.suspend();
}
publicvoid init()
{
setLayout(null);
for(int i=0;i<6;i++)
{
but[i]=new Button(butLab[i]);
add(but[i]);
but[i].addKeyListener(this);
but[i].setBounds(360,(240+30*i),160,25); }
add(scoreLab);
add(scoreTex);
add(speedLab);
add(speedTex);
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); but[1].setEnabled(false);
but[4].setEnabled(false);
infoLab.setBounds(320,75,30,20); infoTex.setBounds(360,75,160,20); infoTex.setBackground(Color.white); noStop.setBounds(360,360,160,25);