整个游戏我分为10个java文件:先是俄罗斯方块的形状存储statefang.java,代码如下:packagecom.example.eluosifangkuai;publicclassstatefang{//方块的逻辑类publicstaticint[][][]state=newi整个游戏我分为10个java文件:先是俄罗斯方块的形状存储statefang.java,代码如下:packagecom.example.eluosifangkuai;publicclassstatefang{//方块的逻辑类publicstaticint[][][]state=newint[][][]{{//I{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0}},{//I1{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,1,1,1}},{//I2{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0}},{//I3{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,1,1,1}},{//I4{0,0,0,0},{0,0,0,0},{0,1,1,0},{0,1,1,0}},{//O5{0,0,0,0},{0,0,0,0},{0,1,1,0},{0,1,1,0}},{//O6{0,0,0,0},{0,0,0,0},{0,1,1,0},{0,1,1,0}},{//O7{0,0,0,0},{0,0,0,0},{0,1,1,0},{0,1,1,0}},{//O8{0,0,0,0},{0,1,0,0},{0,1,0,0},{0,1,1,0}},{//L9{0,0,0,0},{0,0,0,0},{1,1,1,0},{1,0,0,0}},{//L10{0,0,0,0},{0,1,1,0},{0,0,1,0},{0,0,1,0}},{//L11{0,0,0,0},{0,0,0,0},{0,0,1,0},{1,1,1,0}},{//L12{0,0,0,0},{0,0,1,0},{0,0,1,0},{0,1,1,0}},{//J13{0,0,0,0},{0,0,0,0},{1,0,0,0},{1,1,1,0}},{//J14{0,0,0,0},{0,1,1,0},{0,1,0,0},{0,1,0,0}},{//J15{0,0,0,0},{0,0,0,0},{1,1,1,0},{0,0,1,0}},{//J16{0,0,0,0},{0,0,0,0},{0,1,0,0},{1,1,1,0}},{//T17{0,0,0,0},{0,0,1,0},{0,1,1,0},{0,0,1,0}},{//T18{0,0,0,0},{0,0,0,0},{1,1,1,0},{0,1,0,0}},{//T19{0,0,0,0},{1,0,0,0},{1,1,0,0},{1,0,0,0}},{//T20{0,0,0,0},{0,0,0,0},{0,1,1,0},{1,1,0,0}},{//S21{0,0,0,0},{0,1,0,0},{0,1,1,0},{0,0,1,0}},{//S22{0,0,0,0},{0,0,0,0},{0,1,1,0},{1,1,0,0}},{//S23{0,0,0,0},{0,1,0,0},{0,1,1,0},{0,0,1,0}},{//Z24{0,0,0,0},{0,0,0,0},{1,1,0,0},{0,1,1,0}},{//Z25{0,0,0,0},{0,0,1,0},{0,1,1,0},{0,1,0,0}},{//Z26{0,0,0,0},{0,0,0,0},{1,1,0,0},{0,1,1,0}},{//Z27{0,0,0,0},{0,0,1,0},{0,1,1,0},{0,1,0,0}}//28};}我们当然还要编写音乐播放类,资源播放类了等等。。。。。。我把所有的图片资源编写在一个类里面,叫做GameResources.java,具体代码如下:packagecom.example.eluosifangkuai;importandroid.content.Context;importandroid.content.res.Resources;importandroid.graphics.Bitmap;importandroid.graphics.Canvas;importandroid.graphics.Bitmap.Config;importandroid.graphics.Paint;importandroid.graphics.drawable.Drawable;publicclassGameResources{Resourcesm_Resources;//资源类Canvasm_Canvas;//画布Bitmapm_Bitmaphc=null;//缓冲位图Bitmapm_Bitmap01=null;//图像位图Bitmap[]m_Bitmaps=newBitmap[8];//精灵位图Bitmapscore;//分数位图BitmapPlay;//开始位图BitmapLevel;publicGameResources(Contextcontext)//初始化装载位图{m_Resources=context.getResources();for(inti=0;i7;i++){m_Bitmaps[i]=createImage(m_Resources.getDrawable(R.drawable.cube_960_011+i),18,18);}m_Bitmap01=createImage(m_Resources.getDrawable(R.drawable.bgcatcher),320,480);m_Bitmaps[7]=createImage(m_Resources.getDrawable(R.drawable.main11),320,402);score=createImage(m_Resources.getDrawable(R.drawable.score),87,150);Play=createImage(m_Resources.getDrawable(R.drawable.b7),320,480);Level=createImage(m_Resources.getDrawable(R.drawable.levelup),139,88);m_Bitmaphc=Bitmap.createBitmap(320,480,Config.ARGB_8888);m_Canvas=newCanvas(m_Bitmaphc);bitmapB();}publicvoidbitmapB(){Paintm_Paint=newPaint();m_Paint.setAntiAlias(true);m_Paint.setAlpha(220);m_Canvas.drawBitmap(m_Bitmap01,0,0,null);}publicstaticBitmapcreateImage(Drawabletile,intw,inth){//双缓冲加载位图资源Bitmapbitmap=Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);Canvascanvas=newCanvas(bitmap);tile.setBounds(0,0,w,h);tile.draw(canvas);returnbitmap;}}音乐播放类,MusicPlay.java具体代码如下:packagecom.example.eluosifangkuai;importjava.util.HashMap;importjava.util.Map;importandroid.content.Context;importandroid.media.AudioManager;importandroid.media.MediaPlayer;importandroid.media.SoundPool;publicclassMusicPlay{publicstaticMediaPlayerm_MediaPlay;//背景播放器publicstaticMediaPlayerm_MenuPlay;publicstaticSoundPoolsoundPool;//声明音效播放器publicMediaPlayerm_FastDown;privatestaticbooleanmusicSwitch=true;//音乐开关privatestaticbooleansoundSwitch=true;//音效开关privatestaticMapInteger,IntegersoundMap;//音效资源id与加载过后的音源id的映射关系表privatestaticContextcontext;publicstaticvoidinItMusicPlay(Contextc){context=c;}publicstaticvoidinItMenuMusicPlay(Contextc){context=c;}//初始化背景播放器publicstaticvoidBgMediaplayer(){m_MediaPlay=MediaPlayer.create(context,R.raw.gamebg);m_MediaPlay.setLooping(true);}publicstaticvoidmenuMusic(){m_MenuPlay=MediaPlayer.create(context,R.raw.menubg);m_MenuPlay.setLooping(true);}publicstaticvoidpauseMusic(){if(m_MediaPlay.isPlaying()){m_MediaPlay.pause();}}publicstaticvoidpauseMenuMusic(){if(m_MenuPlay.isPlaying()){m_MenuPlay.pause();}}publicstaticvoidstartMusic(){if(musicSwitch){m_MediaPlay.start();}}publicstaticvoidstartMenuMusic(){if(musicSwitch){m_MenuPlay.start();}}publicstaticvoidreleaseMusic(){if(m_MediaPlay!=null){m_MediaPlay.release();}}publicstaticvoidreleaseMenuMusic(){if(m_MenuPlay!=null){m_MenuPlay.release();}}//设置音乐开关publicstaticvoidsetMusicSwitch(booleanmusicSwitch){MusicPlay.musicSwitch=musicSwitch;if(MusicPlay.musicSwitch){m_MediaPlay.start();}else{m_MediaPlay.stop();}}publicstaticvoidinItSound(){soundPool=newSoundPool(8,AudioManager.STREAM_MUSIC,0);soundMap=newHashMapInteger,Integer();//将音效资源加入soundPool,并做成soundMap映射soundMap.put(R.raw.action,soundPool.load(context,R.raw.action,1));soundMap.put(R.raw.fastdown,soundPool.load(context,R.raw.fastdown,1));soundMap.put(R.raw.rotation,s