【正文】
d smartphone developing fast . Android occupies a large share in the market . Android game application is successful, it make a person see that mobile games on the Android platform of the huge development space. Based on this,we using Eclipse and Android ADT as integrated development platform, to develop the Android game application. This application for Android plane war games include six operating interface, respectively as the start screen, the game interface and set interface, Win interface, Lose interface. Players can choose interface to play the game. As the mobile phone game background music is indispensable, the application play different background music in different interface, players can also set the size of the background music in setting interface. This application using the Android SurfaceView to draw game interface, game interface pleasing to the eye by people to play. I n order to give players a good game environment , the control module of game should be simple, easy to operate. Keywords : Android Programing。 隨著游戲關(guān)卡不斷提高,其難度也更大,刺激性也更強(qiáng)。 可行性分析 該系統(tǒng)采用 Eclipse 集成 Android ADT 為開(kāi)發(fā)平臺(tái)進(jìn)行 APP 開(kāi) 發(fā)。 洛陽(yáng)師范學(xué)院 2020 屆本科生畢業(yè)設(shè)計(jì) 2 第 2 章 系統(tǒng)需求分析 用戶功能需求分析 由于本程序簡(jiǎn)單易操作,交互性好,對(duì)用戶沒(méi)什么特別要求。各個(gè) Activity 之間的切換要快速( PS:它們各自的背景音樂(lè)也要隨之切換,給用戶 以 順暢、自然的感覺(jué))。 用戶的操作基本可以劃分為 “ 開(kāi)始游戲 ” , “ 設(shè)置游戲 ” , “ 玩游戲 ” , “ 查看分?jǐn)?shù) ” , “ 退出游戲 ” 這五個(gè)用例。 用來(lái)存儲(chǔ)用戶基本信息的positor_table 的字段信息如圖 41 所示。使用了最簡(jiǎn)單的單例,并未從線程安全的角度進(jìn)行進(jìn)一步的限制,原因在于考慮到 當(dāng)前應(yīng)用中只有 3 個(gè) Activity 使用了 DAO,由圖 42 可知Activity 之間的切換類(lèi)似于進(jìn)程對(duì)于 CPU 的占用一樣,當(dāng)前顯示在界面上的 Activity 是活動(dòng)狀態(tài)而其他 Activity 則是掛起狀態(tài),因此不必?fù)?dān)心它們的線程同時(shí)去創(chuàng)建 DAO 對(duì)象以引起當(dāng)前系統(tǒng)中多個(gè) DAO 對(duì)象的狀況。 helper = new SkyGameDataBaseHelper(context,1)。 (sql, null, values)。 if(() 0){ int count = 0。 } try { ()。 Android 作為目前主流的移動(dòng)操作系統(tǒng),完全符合 SQLite 占用資源少的優(yōu)勢(shì),故在Android 平臺(tái)上,集成了一個(gè) 嵌入式 關(guān)系型數(shù)據(jù)庫(kù) — SQLite。// 設(shè)置當(dāng)前 activity 調(diào)用的layout //其他操作 } BroadcastReceiver 由于本應(yīng) 用是有多個(gè) Activity 為了解決多個(gè) Activity 在其中任意一個(gè) Activity 結(jié)束時(shí)都會(huì)相應(yīng)一起退出系統(tǒng),因此針對(duì)每一個(gè) Activity 設(shè)置一個(gè) BroadcastReceiver 來(lái)接收廣播,一旦接收到廣播當(dāng)前 Activity 自動(dòng)退出 。 MediaPlayer( 媒體播放器 ) 本應(yīng)用使用 Android 的 MediaPlayer 來(lái)演奏每一個(gè)頁(yè)面的背景音樂(lè)。 } catch (SecurityException e) { // TODO Autogenerated catch block ()。 monitor = new Monitor()。 if((eventX = START_X)amp。 } if(action == ){ startButton = (getResources(), )。 (eventY = OPTION_Y)amp。 } } else if((eventX = SCORE_X)amp。 } if(action == ){ scoreButton = (getResources(), )。 (eventY = EXIT_Y)amp。 (EXIT)。 sr = new SkyGameScreenRollView(this)。 ContextMenu 的方法如下: res/menu/** 的菜單 ( 當(dāng)前應(yīng)用使用的該方法 )。 } 在游戲界面的 SkyGameScreenRollActivity 的方法 onOptionsItemSelected(MenuItem item)中為每個(gè)菜單選項(xiàng)編寫(xiě)響應(yīng)事件,具體使用方法如下所示: public boolean onOptionsItemSelected(MenuItem item) { // TODO Autogenerated method stub Intent intent = null。 break。 } 發(fā)送短信 在用戶贏得一關(guān)的時(shí)候會(huì)發(fā)送一條信息“通過(guò)第 N 關(guān)”,實(shí)現(xiàn)該功能的代碼如下: private SmsManager sms = null。 float x = ()。 y = ()+()){ if(action == ){ playerIsTouch = true。 (intent)。 飛機(jī)中彈序列如圖 412 所示: 圖 412 飛機(jī)中彈序列圖 血條 繪制玩家飛機(jī)血線和 Boss 血線的邏輯是相同的,在統(tǒng)計(jì)飛機(jī)中彈次數(shù)的情況下使用圖洛陽(yáng)師范學(xué)院 2020 屆本科生畢業(yè)設(shè)計(jì) 26 413 中的各個(gè)小圖對(duì)血線進(jìn)行繪制。 ( blood, 0, viewHeight (), null)。 } } 設(shè)置界面 當(dāng)前界面使用的是普通的 layout,生成的設(shè)置界面如圖 415 所示: 圖 415 設(shè)置界面 洛陽(yáng)師范學(xué)院 2020 屆本科生畢業(yè)設(shè)計(jì) 28 ?xml version= encoding=utf8? LinearLayout xmlns:android= android:layout_width=match_parent android:layout_height=match_parent android:orientation=vertical LinearLayout android:layout_width=match_parent android:layout_height=wrap_content TextView android:id=+id/tv_option_sound android:layout_width=0dp android:layout_height=wrap_content android:layout_weight=1 android:gravity=center android:text=string/tv_option_sound android:textSize=20dp / SeekBar android:id=+id/option_sound_seekBar android:layout_width=0dp android:layout_height=wrap_content android:layout_weight=4 / /LinearLayout RadioGroup android:id=+id/option_grade_radio_group android:layout_width=wrap_content android:layout_height=wrap_content RadioButton android:id=+id/option_grade_simple android:layout_width=wrap_content android:layout_height=wrap_content android:checked=true android:text=string/option_radioButton_simple / RadioButton android:id=+id/option_grade_middle android:layout_width=wrap_content android:layout_height=wrap_content android:text=string/option_radioButton_middle / RadioButton android:id=+id/option_grade_difficult android:layout_width=wrap_content android:layout_height=wrap_content android:text=string/option_radioButton_difficult / /RadioGroup 基于 Android 的飛機(jī)大戰(zhàn)游戲設(shè)計(jì)與開(kāi)發(fā) 29 LinearLayout android:layout_width=match_parent android:layout_height=wrap_content Button android:id=+id/btn_make_sure android:layout_width=wrap_content android:layout_height=wrap_content android:text=string/btn_confirm / Button android:id=+id/btn_cancle android:layout_width=wrap_content android:layout_height=wrap_content android:text=string/btn_cancle / /LinearLayout /LinearLayout SeekBaramp。 (maxProgress)。 (rdGroupCheckedrdId, rdId)。 基于 Android 的飛機(jī)大戰(zhàn)游戲設(shè)計(jì)與開(kāi)發(fā) 31 private Button btnCancle = null。 (rdGroupCheckedrdId, rdId)。 (rdId)。 initSeekBarProgress()。 ()。 } public boolean onOptionsItemSelec