資源描述:
《俄羅斯方塊游戲源代碼4》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、俄羅斯方塊游戲源代碼4.txt女人謹記:一定要吃好玩好睡好喝好。一旦累死了,就別的女人花咱的錢,住咱的房,睡咱的老公,泡咱的男朋友,還打咱的娃。JAVA游戲編程之三----j2me手機游戲入門開發(fā)--俄羅斯方塊_4_增加消除行聲音收藏之前的游戲代碼中都未加聲音,不少網(wǎng)友在做別業(yè)設(shè)計時要求增加聲音,其實聲音還是比較好做的!但手機真機上可能會有不同的問題,但在模擬器上一般都沒什么問題,所以真機上的問題就具體問題具體分析吧!這里給出一個很簡單的聲音應(yīng)用。在原俄羅斯方塊_3的代碼基礎(chǔ)上增加一個聲音類!示例代碼如下--
2、------------------------------------------------------------------------------viewplaincopytoclipboardprint?packagecode;importjava.io.*;importjavax.microedition.media.Manager;importjavax.microedition.media.MediaException;importjavax.microedition.media.Playe
3、r;publicclassSound{publicstaticPlayerm_sounds;publicstaticintm_currentSoundID=-1;publicstaticbooleans_sound_bg_On=false;privatestaticfinalStringSOUND_FILENAME="/pics/newmsg.wav";//0.背景聲音publicstaticfinalvoidinitSound(){if(m_sounds!=null)return;try{DataInput
4、Streamdis=newDataInputStream("".getClass().getResourceAsStream(SOUND_FILENAME));byte[]soundBuffer=newbyte[dis.available()];dis.read(soundBuffer);InputStreamis=newByteArrayInputStream(soundBuffer);m_sounds=Manager.createPlayer(is,"audio/x-wav");m_sounds.real
5、ize();m_sounds.prefetch();}catch(Exceptione){e.printStackTrace();}}publicstaticvoidplaySound(intsoundID){playSound(soundID,1);}publicstaticvoidplaySound(intsoundID,intloopCount){try{if(m_sounds==null)return;if(m_sounds.getState()==javax.microedition.media.P
6、layer.STARTED)return;m_currentSoundID=soundID;m_sounds.setMediaTime(0);m_sounds.setLoopCount(loopCount);m_sounds.start();Thread.sleep(50);//maybethiscanhelpforsoundproblems}catch(Exceptione){e.printStackTrace();}}privatestaticvoidstopSound()throwsException{
7、try{if(m_sounds==null)return;if(m_sounds.getState()==javax.microedition.media.Player.STARTED)m_sounds.stop();if(m_sounds.getState()==javax.microedition.media.Player.PREFETCHED)m_sounds.deallocate();m_currentSoundID=-1;}catch(Exceptione){e.printStackTrace();
8、}}publicstaticintreadFileToMemory(StringfileName,byte[]buffer){java.io.InputStreamfile=null;intsize;try{file=fileName.getClass().getResourceAsStream(fileName);size=file.read(buffer);file.close();file=n