智能終端軟件開發(fā)-課程設(shè)計(jì)報(bào)告_第1頁
智能終端軟件開發(fā)-課程設(shè)計(jì)報(bào)告_第2頁
智能終端軟件開發(fā)-課程設(shè)計(jì)報(bào)告_第3頁
智能終端軟件開發(fā)-課程設(shè)計(jì)報(bào)告_第4頁
智能終端軟件開發(fā)-課程設(shè)計(jì)報(bào)告_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

實(shí)用文檔PAGE中國(guó)地質(zhì)大學(xué)(武漢)智能終端軟件開發(fā)標(biāo)題:智能終端課程設(shè)計(jì)指導(dǎo)老師:徐戰(zhàn)亞班級(jí):116101學(xué)號(hào):20101002130學(xué)生:高亞兵2014年1月13日摘要本次課程設(shè)計(jì)主要內(nèi)容是雙人五子棋游戲的開發(fā)。主要內(nèi)容是界面布局、判斷輸贏,記錄輸贏次數(shù)。開發(fā)想法來源,純屬娛樂。關(guān)鍵詞:益智游戲Android

第一部分分析游戲游戲功能簡(jiǎn)述界面布局 按照象棋的表格圖案繪制布局,在畫布上設(shè)計(jì)表格,并標(biāo)記紅黑方位置。棋子連線分析標(biāo)明五子棋的顏色,記錄分析棋子的位置,判斷是否取勝。記錄輸贏次數(shù)記錄紅黑雙方輸贏次數(shù)。二、游戲核心技術(shù)1、基本技術(shù)組成 判斷路徑,數(shù)據(jù)結(jié)構(gòu)算法。2、關(guān)鍵技術(shù)難點(diǎn)分析1、技術(shù)難點(diǎn) 分析棋子連線是否可以取勝。2、作為難點(diǎn)的原因 棋子之間有三種連線情況,橫向連續(xù)連接、縱向連續(xù)連接、對(duì)角線連續(xù)連接。3、準(zhǔn)備突破方法將同類棋子之間,有位置關(guān)系的棋子進(jìn)行進(jìn)棧處理,如果在棋盤范圍內(nèi),有連續(xù)的五個(gè)棋子則為取勝。第二部分設(shè)計(jì)與開發(fā)前期準(zhǔn)備工作軟件環(huán)境:WindowsAndroidSDK;Eclipse(windows版)環(huán)境配置:Windows下AndroidSDK安裝。安裝步驟:1、下載SDK包,Android-SDK,下載地址:/tools/sdk/ndk/index.html2、配置SDK導(dǎo)入sdk文件游戲預(yù)期效果UI設(shè)計(jì)背景畫布選擇恰當(dāng),布局清晰,結(jié)構(gòu)清晰,使用簡(jiǎn)單。棋盤設(shè)計(jì)方格大小,連線之間的距離適中,確保棋子在連線上,避免棋子在棋盤上混亂擺放。提示框出現(xiàn)下棋位置不在棋盤內(nèi)或者不在合法范圍內(nèi)是出現(xiàn)錯(cuò)誤提示當(dāng)由一方取得勝利時(shí),出現(xiàn)提示框。開發(fā)過程1、布局設(shè)計(jì)packagecn.m.xys;//Downloadbyimportandroid.app.Activity;importandroid.os.Bundle;importandroid.view.Display;importandroid.view.KeyEvent;importandroid.view.Window;importandroid.view.WindowManager;publicclassFiveChessActivityextendsActivity{GameViewgameView=null;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState); //隱藏標(biāo)題欄 requestWindowFeature(Window.FEATURE_NO_TITLE); //全屏顯示 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //獲取屏幕寬高 Displaydisplay=getWindowManager().getDefaultDisplay(); //現(xiàn)實(shí)GameView GameView.init(this,display.getWidth(),display.getHeight()); gameView=GameView.getInstance(); setContentView(gameView);}@OverridepublicbooleanonKeyDown(intkeyCode,KeyEventevent){ returnsuper.onKeyDown(keyCode,event);}}2、算法設(shè)計(jì)packagecn.m.xys;//Downloadbyimportandroid.app.Activity;importandroid.content.Context;importandroid.content.res.Resources;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Matrix;importandroid.graphics.Paint;importandroid.graphics.Rect;importandroid.view.MotionEvent;importandroid.view.SurfaceHolder;importandroid.view.SurfaceView;/***@authorAdministrator**/publicclassGameViewextendsSurfaceViewimplementsConst,SurfaceHolder.Callback,Runnable{ staticGameViewsInstance=null; publicstaticvoidinit(ActivitymActivity,intscreenWidth,intscreenHeight) { sInstance=newGameView(mActivity,screenWidth,screenHeight); } publicstaticGameViewgetInstance() { returnsInstance; } //控制循環(huán) booleanmbLoop=false; //定義SurfaceHolder對(duì)象 SurfaceHoldermSurfaceHolder=null; publicstaticPaintsPaint=null; publicstaticCanvassCanvas=null; publicstaticResourcessResources=null; privateintmGameState=0; privateintmScreenWidth=0; privateintmScreenHeight=0; publicint[][]mGameMap=null; privateintmMapHeightLengh=0; privateintmMapWidthLengh=0; privateintmMapIndexX=0; privateintmMapIndexY=0; publicintmCampTurn=0; publicintmCampWinner=0; privatefloatmTitleSpace=0; privateintmTitleHeight=0; privatefloatmTitleIndex_x=0; privatefloatmTitleIndex_y=0; BitmapbitmapBg=null; BitmapmBlack=null; BitmapmWhite=null; ContextmContext=null; publicGameView(Activityactivity,intscreenWidth,intscreenHeight) { super(activity); sPaint=newPaint(); sPaint.setAntiAlias(true); sResources=getResources(); mContext=activity; mScreenWidth=screenWidth; mScreenHeight=screenHeight; mSurfaceHolder=this.getHolder(); mSurfaceHolder.addCallback(this); setFocusable(true); mbLoop=true; bitmapBg=CreatMatrixBitmap(R.drawable.status,mScreenWidth,mScreenHeight); mBlack=BitmapFactory.decodeResource(GameView.sResources,R.drawable.ai); mWhite=BitmapFactory.decodeResource(GameView.sResources,R.drawable.human); mTitleSpace=(float)mScreenWidth/CHESS_WIDTH; mTitleHeight=mScreenHeight/3; mTitleIndex_x=(float)(mTitleSpace/2); mTitleIndex_y=(float)(mTitleSpace/2); setGameState(GS_GAME); } publicvoidsetGameState(intnewState) { mGameState=newState; switch(mGameState) { caseGS_GAME: mGameMap=newint[CHESS_HEIGHT][CHESS_WIDTH]; mMapHeightLengh=mGameMap.length; mMapWidthLengh=mGameMap[0].length; mCampTurn=CAMP_HERO; break; } } protectedvoidDraw() { sCanvas=mSurfaceHolder.lockCanvas(); if(mSurfaceHolder==null||sCanvas==null) { return; } RenderGame(); mSurfaceHolder.unlockCanvasAndPost(sCanvas); } privatevoidRenderGame() { switch(mGameState) { caseGS_GAME: DrawRect(Color.WHITE,0,0,mScreenWidth,mScreenHeight); RenderMap(); break; caseGS_END: DrawRect(Color.RED,0,0,mScreenWidth,mScreenHeight); DrawString(Color.WHITE,sResources.getString(mCampWinner)+"勝利點(diǎn)擊繼續(xù)游戲",50,50); break; } } privatevoidRenderMap() { inti,j; DrawImage(bitmapBg,0,0,0); for(i=0;i<mMapHeightLengh;i++) { for(j=0;j<mMapWidthLengh;j++) { intCampID=mGameMap[i][j]; floatx=(j*mTitleSpace)+mTitleIndex_x; floaty=(i*mTitleSpace)+mTitleHeight+mTitleIndex_y; if(CampID==CAMP_HERO) { DrawImage(mBlack,x,y,ALIGN_VCENTER|ALIGN_HCENTER); } elseif(CampID==CAMP_ENEMY) { DrawImage(mWhite,x,y,ALIGN_VCENTER|ALIGN_HCENTER); } } } } privatevoidDrawRect(intcolor,intx,inty,intwidth,intheight) { sPaint.setColor(color); sCanvas.clipRect(x,y,width,height); sCanvas.drawRect(x,y,width,height,sPaint); } privatevoidDrawString(intcolor,Stringstr,intx,inty) { sPaint.setColor(color); sCanvas.drawText(str,x,y,sPaint); } @Override publicbooleanonTouchEvent(MotionEventevent) { intx=(int)event.getX(); inty=(int)event.getY(); switch(event.getAction()) { caseMotionEvent.ACTION_DOWN: UpdateTouchEvent(x,y); break; caseMotionEvent.ACTION_MOVE: break; caseMotionEvent.ACTION_UP: break; } returnsuper.onTouchEvent(event); } publicbooleanCheckPiecesMeet(intCamp) { intMeetCount=0; //橫向 for(inti=0;i<CALU_ALL_COUNT;i++) { intindex=mMapIndexX-CALU_SINGLE_COUNT+i; if(index<0||index>=mMapWidthLengh) { if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } MeetCount=0; continue; } if(mGameMap[mMapIndexY][index]==Camp) { MeetCount++; if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } }else { MeetCount=0; } } //縱向 MeetCount=0; for(inti=0;i<CALU_ALL_COUNT;i++) { intindex=mMapIndexY-CALU_SINGLE_COUNT+i; if(index<0||index>=mMapHeightLengh) { if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } MeetCount=0; continue; } if(mGameMap[index][mMapIndexX]==Camp) { MeetCount++; if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } }else { MeetCount=0; } } //右斜 MeetCount=0; for(inti=0;i<CALU_ALL_COUNT;i++) { intindexX=mMapIndexX-CALU_SINGLE_COUNT+i; intindexY=mMapIndexY-CALU_SINGLE_COUNT+i; if((indexX<0||indexX>=mMapWidthLengh)||(indexY<0||indexY>=mMapHeightLengh)) { if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } MeetCount=0; continue; } if(mGameMap[indexY][indexX]==Camp) { MeetCount++; if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } }else { MeetCount=0; } } //左斜 MeetCount=0; for(inti=0;i<CALU_ALL_COUNT;i++) { intindexX=mMapIndexX-CALU_SINGLE_COUNT+i; intindexY=mMapIndexY+CALU_SINGLE_COUNT-i; if((indexX<0||indexX>=mMapWidthLengh)||(indexY<0||indexY>=mMapHeightLengh)) { if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } MeetCount=0; continue; } if(mGameMap[indexY][indexX]==Camp) { MeetCount++; if(MeetCount==CALU_SINGLE_COUNT) { returntrue; } }else { MeetCount=0; } } returnfalse; } privatevoidUpdateTouchEvent(intx,inty) { switch(mGameState) { caseGS_GAME: if(x>0&&y>mTitleHeight) { mMapIndexX=(int)(x/mTitleSpace); mMapIndexY=(int)((y-mTitleHeight)/mTitleSpace); if(mMapIndexX>mMapWidthLengh) { mMapIndexX=mMapWidthLengh; } if(mMapIndexX<0) { mMapIndexX=0; } if(mMapIndexY>mMapHeightLengh) { mMapIndexY=mMapHeightLengh; } if(mMapIndexY<0) { mMapIndexY=0; } if(mGameMap[mMapIndexY][mMapIndexX]==CAMP_DEFAULT) { if(mCampTurn==CAMP_HERO) { mGameMap[mMapIndexY][mMapIndexX]=CAMP_HERO; if(CheckPiecesMeet(CAMP_HERO)) { mCampWinner=R.string.Role_black; setGameState(GS_END); } else { mCampTurn=CAMP_ENEMY; } } else { mGameMap[mMapIndexY][mMapIndexX]=CAMP_ENEMY; if(CheckPiecesMeet(CAMP_ENEMY)) { mCampWinner=R.string.Role_white; setGameState(GS_END); }else { mCampTurn=CAMP_HERO; } } } } break; caseGS_END: setGameState(GS_GAME); break; } } publicbooleanisCheckInvite(Stringbody) { if(body.indexOf("invite")>=0) { if(mGameState!=GS_INVITING&&mGameState!=GS_COMFIRE&&mGameState!=GS_GAME) { returntrue; } } returnfalse; } /** *創(chuàng)建一個(gè)縮小或放大的新圖片 * *@paramresourcesID *@paramscr_width *@paramres_height *@return */ privateBitmapCreatMatrixBitmap(intresourcesID,floatscr_width,floatres_height) { BitmapbitMap=null; bitMap=BitmapFactory.decodeResource(sResources,resourcesID); intbitWidth=bitMap.getWidth(); intbitHeight=bitMap.getHeight(); floatscaleWidth=scr_width/(float)bitWidth; floatscaleHeight=res_height/(float)bitHeight; Matrixmatrix=newMatrix(); matrix.postScale(scaleWidth,scaleHeight); bitMap=Bitmap.createBitmap(bitMap,0,0,bitWidth,bitHeight,matrix,true); returnbitMap; } /** *繪制一個(gè)字符串 * *@paramtext *@paramx *@paramy *@paramanchor *@paramCanvas *@parampaint */ privatevoidDrawString(intcolor,Stringtext,intx,inty,intanchor) { Rectrect=newRect(); sPaint.getTextBounds(text,0,text.length(),rect); intw=rect.width(); inth=rect.height(); inttx=0; intty=0; if((anchor&ALIGN_RIGHT)!=0) { tx=x-w; } elseif((anchor&ALIGN_HCENTER)!=0) { tx=x-(w>>1); } else { tx=x; } if((anchor&ALIGN_TOP)!=0) { ty=y+h; } elseif((anchor&ALIGN_VCENTER)!=0) { ty=y+(h>>1); } else { ty=y; } sPaint.setColor(color); sCanvas.drawText(text,tx,ty,sPaint); } /** *繪制一張圖片可以選擇圖片的錨點(diǎn)位置 * *@paramcanvas *@parampaint *@parambitmap *@paramx *@paramy *@paramangle */ privatevoidDrawImage(Bitmapbitmap,floatx,floaty,intanchor) { intw=bitmap.getWidth(); inth=bitmap.getHeight(); floattx=0; floatty=0; if((anchor&ALIGN_RIGHT)!=0) { tx=x-w; } elseif((anchor&ALIGN_HCENTER)!=0) { tx=x-(w>>1); } else { tx=x; }

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論