freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于j2me平臺的手機(jī)游戲貪吃蛇程序的設(shè)計與實現(xiàn)(編輯修改稿)

2024-07-16 12:33 本頁面
 

【文章內(nèi)容簡介】 if(bgmap/2100) (temp_bg1, i*16, 0, |)。//被繪制的圖像,X軸Y軸,基點 else (temp_bg2, i*16, 0, |)。 }/****裝載障礙物****/ bg = null。//釋放實例化對象可以使用bg=nul。 temp_bg1 = null。//釋放實例化對象可以使用temp=nul。 temp_bg2 = null。//釋放實例化對象可以使用temp=nul。 ()。//釋放實例化對象語句 } catch(Exception e) { ()。 } rePlay( level )。 //()。 }/**裝載線程,預(yù)執(zhí)行**/ public void start() { /**開始由SingActive決定聲音的進(jìn)入與否**/ if(==true) ().loadResourse(soundmax)。 //().start()。 isPlay=true。 thread =new Thread(this)。 ()。 } /**當(dāng)用戶按下?lián)芴栨I時游戲暫停下來**/ public void keyPressed(int keyCode) { if (keyCode == FIRE) { tempcontinue+=1。 if(tempcontinue%2!=0){ stop()。 ().stop()。 } else start()。 // ()。 } } /**獲得鍵盤的動作**/ private void input() { int keyStates=getKeyStates()。 if ((keyStates amp。 LEFT_PRESSED) != 0) (2)。 else if ((keyStates amp。 RIGHT_PRESSED) != 0) (3)。 else if ((keyStates amp。 UP_PRESSED) != 0) (0)。 else if ((keyStates amp。 DOWN_PRESSED) != 0) (1)。 /**按鍵代碼暫停游戲**/ else if ((keyStates amp。 KEY_POUND) !=0) ()。 } public void stop(){ isPlay=false。}/**線程開始執(zhí)行* * @throws InterruptedException */ public void run() { Graphics g=getGraphics()。 //獲取Graphics對象 while(isPlay) { long start =()。 input()。 //獲得鍵盤輸入 paint(g)。 //繪制背景和蛇 isCollide()。 long end=()。 //獲取執(zhí)行完畢的事件 int duration=(int)(endstart)。 if(sleeptime50) sleeptime=50。 if(durationsleeptime) //如果執(zhí)行時間小于循環(huán)預(yù)定時間,則等待到循環(huán)時間 { try{ //wait(3000)。 //start()。 (sleeptimeduration)。} catch(InterruptedException ie){} } } }/**判斷蛇是否與自己重合**/ public void isCollide() { for (int i = 4。i=。i++) { if([0][0]==[i][0]amp。amp。[0][1]==[i][1]) { rePlay(level)。 isPlay=false。 ().stop()。 over=true。 (,over)。 } } }/**負(fù)責(zé)各種圖形的最終繪制**/ public void paint(Graphics g) { (0x000000)。 (0, 0, Width, Height)。/***繪制背景***/ for( int i=0。 imap_bg_x。 i++ ) //繪制背景(草地) { for( int j=0。 jmap_bg_y。 j++ ) { (imgGameBg[ map_bg[i][j] ], j*map_bg_h, i*map_bg_w, |)。 } } /**繪制食物gold***/ for( int i=0。 i。 i++ )//調(diào)用類GIF里的PAINT()來繪制gold圖形 { gold[i].paint(g)。 } /**繪制食物cat***/ for( int i=0。 i。 i++ )//調(diào)用類GIF里的PAINT()來繪制cat圖形 { cat[i].paint(g)。 } /**蛇與四墻碰撞**/ if( ()0 || ()Width || ()0 ||()Height )//蛇頭碰到邊就重來 { rePlay(level)。 isPlay=false。 ().stop()。 over=true。 (,over)。 } /**如果蛇與食物蘑菇發(fā)生碰撞 ***/ for( int i=0。 i。 i++ ) { if( isIntersect((), (), 8, 8, gold[i].pos_x, gold[i].pos_y, gold[i].w, gold[i].h )) { +=1。//蛇的身體自動加1 eatfood+=1。//記錄當(dāng)前屏幕上吃食物的總數(shù) +=1。//記錄吃食物的總數(shù)/**如果蛇的長度達(dá)到規(guī)定的長度則換下一關(guān)**/ if(win) { /****讓聲音停止****/ ().stop()。 isPlay=false。 ()。 } gold[i].setPos()。//碰著食物則重新定位食物的位置 } } /**如果蛇與食物貓發(fā)生碰撞 ***/ for( int i=0。 i。 i++ ) { if( isIntersect((), (), 8, 8, cat[i].pos_x, cat[i].pos_y, cat[i].w, cat[i].h )) { =3。//蛇的身體自動減3 eatfood=3。//記錄當(dāng)前屏幕上吃食物的總數(shù) =3。//記錄吃食物的總數(shù) /**不能讓蛇的長度、吃食物的量、吃食物的總數(shù)小于0**/ if(=1) =1。 if(eatfood=0) eatfood=0。 if(=0) =0。 cat[i].setPos()。//碰著食物貓則重新定位食物的位置 } } /***繪制蛇及字體*****/ /**繪制字體靠左***/ ( 0xf0FF00 )。//黃色 ( font )。 ( eat:+eatfood, 1, 2, 0 )。//字體,X坐標(biāo),Y坐標(biāo),方位 /**繪制字體靠右***/ ( 0xf0FF00 )。 ( font )。 ( eat:+eatfood, 3, 2, 0 )。//字體,X坐標(biāo),Y坐標(biāo),方位 /**繪制字體靠上***/ ( 0xf0FF00 )。 ( font )。 ( eat:+eatfood, 2, 1, 0 )。//字體,X坐標(biāo),Y坐標(biāo),方位 /**繪制字體靠下***/ ( 0xf0FF00 )。 ( font )。 ( eat:+eatfood, 2, 3, 0 )。//字體,X坐標(biāo),Y坐標(biāo),方位 /**繪制字體居中***/ ( 0xFF0000 )。 ( font )。 ( eat:+eatfood, 2, 2, 0 )。//字體,X坐標(biāo),Y坐標(biāo),方位 (g)。 flushGraphics()。 //將緩沖屏幕上的內(nèi)容繪制到手機(jī)屏幕上 }/**碰撞檢測函數(shù)***/ boolean isIntersect(int x1,int y1, int w1, int h1, int x2, int y2, int w2, int h2)//判斷蛇的頭是否和食物重合在做的動作 { if( (x2x1) (w1+w2)/2 amp。amp。 (y2y1) (h1+h2)/2 )//(x2x1):返回一個數(shù)字的絕對值 { return true。 } else return false。 }/***增加蛇的長度***/ public void addSnake(boolean addsnake_n){ addsnake_n=true。 }/**把草地分在數(shù)組map[i][j]中**/public void rePlay( int level ) { map_bg_x = Height/16。//把寬高分成16*16的小塊背景(X軸要多少塊) map_bg_y = Width/16。//(Y軸要多少塊) map_bg = new int[map_bg_x][map_bg_y]。//撲滿整個背景要多少張圖片的總數(shù) for( int i=0。 imap_bg_x。 i++ ) //繪制背景,從Y軸開始繪制 { for( int j=0。 jmap_bg_y。 j++ ) { int r = (maxRand)。//取0到1000的隨機(jī)數(shù),因為max //例:int i = (9)。 09隨即數(shù) 可以用 ()*9。 for( int k=
點擊復(fù)制文檔內(nèi)容
語文相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1