资源描述:
《俄罗斯方块java代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、俄罗斯方块——java源代码提供importjava.awt.*;importjava.awt.event.*;//俄罗斯方块类publicclassERS_BlockextendsFrame{publicstaticbooleanisPlay=false;publicstaticintlevel=1,score=0;publicstaticTextFieldscoreField,levelField;publicstaticMyTimertimer;GameCanvasgameScr;publicstaticvoidmain(String[]argus){ERS_Blockers=newE
2、RS_Block("俄罗斯方块游戏V1.0Author:Vincent");WindowListenerwin_listener=newWinListener();ers.addWindowListener(win_listener);}//俄罗斯方块类的构造方法ERS_Block(Stringtitle){super(title);setSize(600,480);setLayout(newGridLayout(1,2));gameScr=newGameCanvas();gameScr.addKeyListener(gameScr);timer=newMyTimer(gameScr);ti
3、mer.setDaemon(true);timer.start();timer.suspend();add(gameScr);PanelrightScr=newPanel();rightScr.setLayout(newGridLayout(2,1,0,30));rightScr.setSize(120,500);add(rightScr);//右边信息窗体的布局MyPanelinfoScr=newMyPanel();infoScr.setLayout(newGridLayout(4,1,0,5));infoScr.setSize(120,300);rightScr.add(infoScr)
4、;//定义标签和初始值Labelscorep=newLabel("分数:",Label.LEFT);Labellevelp=newLabel("级数:",Label.LEFT);scoreField=newTextField(8);levelField=newTextField(8);scoreField.setEditable(false);levelField.setEditable(false);infoScr.add(scorep);infoScr.add(scoreField);infoScr.add(levelp);infoScr.add(levelField);scorep.s
5、etSize(newDimension(20,60));scoreField.setSize(newDimension(20,60));levelp.setSize(newDimension(20,60));levelField.setSize(newDimension(20,60));scoreField.setText("0");levelField.setText("1");//右边控制按钮窗体的布局MyPanelcontrolScr=newMyPanel();controlScr.setLayout(newGridLayout(5,1,0,5));rightScr.add(contr
6、olScr);//定义按钮playButtonplay_b=newButton("开始游戏");play_b.setSize(newDimension(50,200));play_b.addActionListener(newCommand(Command.button_play,gameScr));//定义按钮LevelUPButtonlevel_up_b=newButton("提高级数");level_up_b.setSize(newDimension(50,200));level_up_b.addActionListener(newCommand(Command.button_leve
7、lup,gameScr));//定义按钮LevelDownButtonlevel_down_b=newButton("降低级数");level_down_b.setSize(newDimension(50,200));level_down_b.addActionListener(newCommand(Command.button_leveldown,gameScr));//定义按钮LevelPauseButt