文档介绍:JAVA游戏编程之三----j2me手机游戏入门开发--俄罗斯方块_4_增加消除行声音收藏之前的游戏代码中都未加声音,不少网友在做别业设计时要求增加声音,其实声音还是比较好做的!但手机真机上可能会有不同的问题,但在模拟器上一般都没什么问题,所以真机上的问题就具体问题具体分析吧!这里给出一个很简单的声音应用。在原俄罗斯方块_3的代码基础上增加一个声音类!示例代码如下--------------------------------------------------------------------------------viewplaincopytoclipboardprint?packagecode;.*;;;;lassSound{publicstaticPlayerm_sounds;publicstaticintm_currentSoundID=-1;publicstaticbooleans_sound_bg_On=false;privatestaticfinalStringSOUND_FILENAME="/pics/";//(){if(m_sounds!=null)return;try{DataInputStreamdis=newDataInputStream("".getClass().getResourceAsStream(SOUND_FILENAME));byte[]soundBuffer=newbyte[()];(soundBuffer);InputStreamis=newByteArrayInputStream(soundBuffer);m_sounds=(is,"audio/x-wav");();();}catch(Exceptione){();}}publicstaticvoidplaySound(intsoundID){playSound(soundID,1);}publicstaticvoidplaySound(intsoundID,intloopCount){try{if(m_sounds==null)return;if(()==)return;m_currentSoundID=soundID;(0);(loopCount);();(50);//maybethiscanhelpforsoundproblems}catch(Exceptione){();}}privatestaticvoidstopSound()throwsException{try{if(m_sounds==null)return;if(()==)();if(()==)();m_currentSoundID=-1;}catch(Exceptione){();}}publicstaticintreadFileToMemory(StringfileName,byte[]buffer){=null;intsize;try{file=().getResourceAsStream(fileName);size=(buffer);();file=null;}catch(Exceptione){return-1;}returnsize;}}packagecode;.*;impor