




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上濱江學院 Android課程設計報告題 目 飛翔的圓(類似Flappy Bird) 專 業(yè)_ _學生姓名_ _ _ _ 學 號_ _二一五年 六月 二十五日目錄 一 安卓應用程序開發(fā)背景1.1開發(fā)背景1.智能手機的市場(1)功能多樣化的智能手機挑戰(zhàn)全球PC出貨量移動互聯(lián)網(wǎng)時代的來臨,直接促進了搭載智能操作系統(tǒng)、具有強大擴展性的智能手機、平板電腦等移動終端產(chǎn)業(yè)的蓬勃發(fā)展。來自美國最大的風險投資機構KPCB的數(shù)據(jù)顯示,全球智能手機出貨量正在以遠高于臺式電腦、筆記本電腦出貨量的速度快速增長,該機構預計2011年全球智能手機出貨量將達到4.13億,超過臺式電腦與筆記本電腦出貨
2、量的總和。(2)智能手機的用戶使用數(shù)量正在高速增長。據(jù)市場調(diào)研機構Gartner信息,2011年全球智能手機的總出貨量將會達到4.68億部,相比2010年實現(xiàn)了57.7%的增長,而谷歌Android操作系統(tǒng)將會在今年之內(nèi)成為全球最大的智能手機操作系統(tǒng)。另外,全球市場調(diào)研機構IDC預計未來5年中國手機市場上,智能手機替代傳統(tǒng)功能手機的趨勢將日益明顯,未來5年中國智能手機市場復合增長率將達到34.1%,人們對IT設備智能化的向往是這一增長率能夠?qū)崿F(xiàn)的主要因素,并且與其他國家相比,中國智能手機市場的發(fā)展空間更加廣闊。(3)操作系統(tǒng)格局預測:Android有望成為智能手機市場主導力量搭載Android
3、操作系統(tǒng)的智能手機目前已經(jīng)成為市場上最炙手可熱的智能產(chǎn)品。來自美國市場研究機構Gartner的數(shù)據(jù)顯示,Android操作系統(tǒng)所占的市場份額從2008年的0.5%急劇增長到2011年的15.94%。開放的源代碼和零成本已經(jīng)讓Android在全世界范圍內(nèi)受到青睞并迅速獲得了主要手機廠商和數(shù)百萬軟件開發(fā)者的支持,Gartner預計,未來Android系統(tǒng)的市場份額有望超過其他操作系統(tǒng),從而成為全球第一大智能手機操作系統(tǒng)。2.安卓手機介紹安卓手機指的是用Android操作系統(tǒng)的手機。安卓(Android)是基于Linux內(nèi)核的操作系統(tǒng),是Google公司在2007年11月5日公布的手機操作系統(tǒng)。同樣
4、都是手機上面用的智能系統(tǒng),安卓的系統(tǒng)是新生系統(tǒng),界面更為華麗,開源性更強,當然因為是新生系統(tǒng),所以在第三方軟件方面暫時還不太多。因此,安卓應用程序的需求還是很迫切的。3.軟件人才需求據(jù)業(yè)內(nèi)統(tǒng)計,目前國內(nèi)的Android研發(fā)人才缺口至少30萬。由于目前Android技術較新,無論是相關書籍、培訓還是大學教育,都處于初級階段,因此Android人才短期將供不應求。從長期來看,隨著各種移動應用和手機游戲等內(nèi)容需求日益增加,也將激勵大中小型手機應用開發(fā)商加大對Android應用的開發(fā)力度,因此Android人才的就業(yè)前景也非常廣泛。綜上所述,在這樣的背景下,安卓有很強的生命力。同時,作為一個新生的系統(tǒng)
5、,其應用程序目前并不多,安卓應用程序的需求還是很迫切的,安卓研發(fā)人才的缺口還很大。這些都促進了我們學習開發(fā)安卓應用程序。1.2開發(fā)環(huán)境安卓應用程序開發(fā)環(huán)境如下:JDK 5 or JDK 6 (JRE alone is not sufficient)Eclipse 3.3 (Europa), 3.4 (Ganymede)Android SDK ADT 0.8.0Eclipse安裝ADT 插件二 安卓應用程序開發(fā)理論與方法1、Activity的相關知識簡單理解Activity 代表一個用戶所能看到的屏幕,Activity 主要是處理一個應用的整體性工作。Activity是最基本的Android 應
6、用程序組件,應用程序中,一個活動通常就是一個單獨的屏幕。每一個活動都被實現(xiàn)為一個獨立的類,并且從活動基類中繼承而來,活動類將會顯示由視圖控件組成的用戶接口,并對事件做出響應。大多數(shù)的應用是由多個屏幕顯示組成,因而要用到多個Activity。(1)Activity的相關方法及相關函數(shù):A、void onCreate(Bundle) 首次啟動時調(diào)用,接受參數(shù):Null or savedInstanceState(保存的以前某些狀態(tài)信息)B、void onStart() 說明了將要顯示給用戶的活動C、void onRestart() 將處于停止狀態(tài)的活動重新顯示給用戶D、void onResume(
7、) 用戶可以開始與活動進行交互時調(diào)用。如動畫播放和音樂播放。E、void onPause() 活動將要進入后臺運行時調(diào)用。(此時前臺啟動了另一個活動)F、void onStop() 不需要某個活動了,就調(diào)用G、void onDestroy()銷毀活動(2)多個Activity之間的跳轉(zhuǎn): 通過Intent類實現(xiàn)屏幕之間的跳轉(zhuǎn)(包括沒有參數(shù)關系和需要傳遞參數(shù)兩種情況)。(3)兩個Activity之間進行數(shù)據(jù)交換: startActivity() 只有Intent一個參數(shù)。public void startSubActivity(Intent intent, int requestCode) (r
8、equestCode:用來標識某一個調(diào)用,一般定義一個常量。)傳過去:函數(shù)原型為: public Intent setData(ContentURI data) 然后,參數(shù)帶到新的Activity后,同樣用Activity.getIntent()函數(shù)可得到當前過來的Intent對象,然后用getData()就取到參數(shù)了。 傳回來:函數(shù)原型為: public final void setResult(int resultCode, String data)2、Intent的相關知識Intent 是描述應用想要做什么。Android 使用了Intent 這個特殊類,實現(xiàn)在屏幕與屏幕之間移動。Int
9、ent 數(shù)據(jù)結構兩個最重要的部分是動作和動作對應的數(shù)據(jù)。Intent類綁定一次操作,它負責攜帶這次操作所需要的數(shù)據(jù)以及操作的類型等。3、Layout 用于用戶界面設計。包含AbsoluteLayout, FrameLayout,GridView, LinearLayout, ListLayout, RadioGroup, TableLayout等等。在本程序中用到的有:(1) 線性布局LinearLayout垂直:android:orientation="vertical“水平:android:orientation="horizontal"(2) 相對布局Rel
10、ativeLayout讓子元素指定它們相對于其他元素的位置(通過ID 來指定)或相對于父布局對象。在RelativeLayout布局里的控件包含豐富的排列屬性: Layout above:控件在指定控件的上方Layout below:控件在指定控件的下方Layout to left of三 小游戲應用程序的設計與實現(xiàn)3.1 擬解決的問題及目標本游戲上手簡單,主旨在讓人在緊張的生活中,獲得游戲的樂趣,程序要實現(xiàn)的目標有如下幾個:(1) 界面流暢(2) 有當前得分(3) 有最高得分(4) 后點擊界面重新開始游戲3.2 總體設計1、游戲的操作流程 點擊屏幕即可開始,當出現(xiàn)游戲界面是,通過點擊屏幕控制
11、圓點的高度,使得圓點觸碰不到上下兩邊的長方形。3.3 詳細設計與編碼實現(xiàn)1、 游戲界面 開始界面,點擊屏幕圓點自動向前移動 當前得分0,點擊屏幕控制圓點高度 觸碰到長方形,游戲結束,點擊屏幕重新開始2、 核心代碼如下: GameBirdActivity類public class GameBirdActivity extends Activity public static GameBirdActivity instance; private LinearLayout gameView;public void onCreate(Bundle savedInstanceState) super.o
12、nCreate(savedInstanceState);instance = this;this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.content_view);/gamegameView = (LinearLayout)this.findViewById(R.id.game_
13、view);gameView.addView(new GameBirdSurfaceView(this);public void showMessage(int level)saveSettingData(level);Intent intent = new Intent(this, LoadingActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);startActivity(intent);public static final String GameBirdSettingsFile = "GameBird
14、_Settings"public static final String Settings_LevelLast = "LevelLast"public static final String Settings_LevelTop = "LevelTop"private void saveSettingData(int level) SharedPreferences gb_settings = getSharedPreferences(GameBirdSettingsFile, 0);gb_settings.edit().putInt(Setti
15、ngs_LevelLast, level).commit();int top = gb_settings.getInt(Settings_LevelTop, 0);if(level>top)gb_settings.edit().putInt(Settings_LevelTop, level).commit();GameBirdSurfaceView類public class GameBirdSurfaceView extends SurfaceView implements Callback, Runnable private SurfaceHolder sfh;private Pain
16、t paint;private Thread th;private boolean flag;private Canvas canvas;private static int screenW, screenH;private static final int GAME_MENU = 0;private static final int GAMEING = 1;private static final int GAME_OVER = -1;private static int gameState = GAME_MENU;private int floor = new int2;private i
17、nt floor_width = 15;private int speed = 3;private int level = new int2;private int level_value = 0;private int bird = new int2;private int bird_width = 10;private int bird_v = 0;private int bird_a = 2;private int bird_vUp = -16;private ArrayList<int> walls = new ArrayList<int>();private
18、ArrayList<int> remove_walls = new ArrayList<int>();private int wall_w = 50;private int wall_h = 100;private int wall_step = 30;public GameBirdSurfaceView(Context context) super(context);sfh = this.getHolder();sfh.addCallback(this);paint = new Paint();paint.setColor(Color.WHITE);paint.set
19、AntiAlias(true);paint.setTextSize(50);paint.setStyle(Style.STROKE); setFocusable(true);setFocusableInTouchMode(true);this.setKeepScreenOn(true);public void surfaceCreated(SurfaceHolder holder) screenW = this.getWidth();screenH = this.getHeight();initGame();flag = true;th = new Thread(this);th.start(
20、);private void initGame() if (gameState = GAME_MENU) floor0 = 0;floor1 = screenH - screenH/5;level0 = screenW/2;level1 = screenH/5;level_value = 0;bird0 = screenW/3;bird1 = screenH/2;walls.clear();floor_width = dp2px(15);speed = dp2px(3);bird_width = dp2px(10);bird_a = dp2px(2);bird_vUp = -dp2px(16)
21、;wall_w = dp2px(45);wall_h = dp2px(100);wall_step = wall_w*4;private int dp2px(float dp)int px = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics();return px;public void myDraw() try canvas = sfh.lockCanvas();if (canvas != null) /clearcanvas.draw
22、Color(Color.BLACK);/backgroundint floor_start = floor0;while(floor_start<screenW)canvas.drawLine(floor_start, floor1, floor_start+floor_width, floor1, paint);floor_start += floor_width*2;/wallfor (int i = 0; i < walls.size(); i+) int wall = walls.get(i);float pts = wall0,0,wall0,wall1,wall0,wa
23、ll1+wall_h,wall0,floor1, wall0+wall_w,0,wall0+wall_w,wall1, wall0+wall_w,wall1+wall_h,wall0+wall_w,floor1,wall0,wall1, wall0+wall_w, wall1,wall0,wall1+wall_h, wall0+wall_w, wall1+wall_h;canvas.drawLines(pts, paint);paint);floor1, paint);/birdcanvas.drawCircle(bird0, bird1, bird_width, paint);/levelc
24、anvas.drawText(String.valueOf(level_value), level0, level1, paint); catch (Exception e) finally if (canvas != null)sfh.unlockCanvasAndPost(canvas);public boolean onTouchEvent(MotionEvent event) if(event.getAction() = MotionEvent.ACTION_DOWN)switch (gameState) case GAME_MENU:gameState = GAMEING; /bir
25、d_v = bird_vUp; /break;case GAMEING:bird_v = bird_vUp;break;case GAME_OVER:/bird downif(bird1 >= floor1 - bird_width)gameState = GAME_MENU;initGame();break;return true;public boolean onKeyDown(int keyCode, KeyEvent event) if (keyCode = KeyEvent.KEYCODE_BACK) GameBirdActivity.instance.finish();Sys
26、tem.exit(0);return true;return super.onKeyDown(keyCode, event);private int move_step = 0;private void logic() switch (gameState) case GAME_MENU:break;case GAMEING:/birdbird_v+=bird_a;bird1 += bird_v;if(bird1 > floor1 - bird_width)bird1 = floor1 - bird_width;gameState = GAME_OVER;/top /if(bird1<
27、;=bird_width) /bird1=bird_width; /floorif(floor0 < -floor_width)floor0 += floor_width*2;floor0 -= speed;/wallremove_walls.clear(); for (int i = 0; i < walls.size(); i+) int wall = walls.get(i);wall0 -= speed;if(wall0<-wall_w)remove_walls.add(wall);elseif(wall0-bird_width<=bird0&&
28、 wall0+wall_w+bird_width>=bird0&&(bird1<=wall1+bird_width|bird1>=wall1+wall_h-bird_width)gameState = GAME_OVER;int pass = wall0+wall_w+bird_width-bird0;if(pass<0 && -pass<=speed)level_value+;/out of screenif(remove_walls.size()>0)walls.removeAll(remove_walls);/new w
29、allmove_step += speed;if(move_step>wall_step)int wall = new intscreenW, (int)(Math.random()*(floor1-2*wall_h)+0.5*wall_h);walls.add(wall);move_step = 0;break;case GAME_OVER:/birdif(bird1 < floor1 - bird_width)bird_v+=bird_a;bird1 += bird_v;if(bird1 >= floor1 - bird_width)bird1 = floor1 - bi
30、rd_width;elseGameBirdActivity.instance.showMessage(level_value);gameState = GAME_MENU;initGame();break;public void run() while (flag) long start = System.currentTimeMillis();myDraw();logic();long end = System.currentTimeMillis();try if (end - start < 50) Thread.sleep(50 - (end - start); catch (In
31、terruptedException e) e.printStackTrace();public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) public void surfaceDestroyed(SurfaceHolder holder) flag = false;LoadingActivity類public class LoadingActivity extends Activity public void onCreate(Bundle savedInstanceState)
32、super.onCreate(savedInstanceState);this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.loading);final TextView gameStart = (TextView)findViewById(R.id.game_start);AdVie
33、w adView = (AdView)findViewById(R.id.adView);adView.setAdListener(new AdListener() public void onReceiveAd(Ad arg0) gameStart.setVisibility(View.VISIBLE);public void onPresentScreen(Ad arg0) / TODO Auto-generated method stubpublic void onLeaveApplication(Ad arg0) / TODO Auto-generated method stubpublic void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) / TODO Auto-generated method stubpublic void onDismissScreen(Ad arg0) / TODO Auto-generated method stub);View gameMessage = findViewById(R.id.GameMessage);int data = getSettingData();TextView levelMessage = (TextVi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度新能源項目施工團隊派遣服務協(xié)議
- 二零二五年度員工期權激勵計劃執(zhí)行與員工福利協(xié)議
- 二零二五年度特色商業(yè)街區(qū)商鋪轉(zhuǎn)讓合同
- 2025年度鋼構建筑鋼結構加工與施工合同
- 2025年度電子商務平臺合作協(xié)議簽約變更終止全流程手冊
- 二零二五年度醫(yī)療糾紛調(diào)解與醫(yī)療機構糾紛調(diào)解機制建設協(xié)議
- 2025年度電商旺季客服團隊增援服務協(xié)議
- 2025年度金融科技合作入股協(xié)議書
- 二零二五年度城市綜合體工程款房屋抵償協(xié)議
- 二零二五年度電影學院電影包場教學合同
- 【幼兒園園本教研】幼兒表征的教師一對一傾聽策略
- 人教版新教材高一上學期期末考試數(shù)學試卷及答案(共五套)
- 采血知情同意書模板
- Mysql 8.0 OCP 1Z0-908 CN-total認證備考題庫(含答案)
- 教科版二年級科學下冊 (磁鐵能吸引什么) 課件
- 學習探究診斷 化學 必修二
- 冀教2011版九年級英語全一冊《Lesson9ChinasMostFamous“Farmer”》教案及教學反思
- 三年級下冊音樂教學計劃含教學進度安排活動設計word表格版
- 無極繩絞車檢修技術規(guī)范
- 雷鋒生平事跡簡介
- 市政工程施工安全檢查標準
評論
0/150
提交評論