版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、A.B.C.a) b) ) dA.B.C.a) b) ) d) 開發(fā)環(huán)境:Netbeans基于J2ME 1StartGame.javaimportimportimportimportimportimport基于J2ME 1StartGame.javaimportimportimportimportimportimportimportimportpublicclassStartGameextendsListimplementsCommandListenerprivateCommandoknewCommand(選擇Command.OKprivateImagepublicStartGame()sup
2、er(五子棋游戲Image this.append(開始游戲this.append(游戲說明publicvoidcommandAction(Commandc,Displayabled)this.append(開始游戲this.append(游戲說明publicvoidcommandAction(Commandc,Displayabled) () elseif游戲說明.equals(this.getString(this.getSelectedIndextry image=catch(IOExceptione)Alertalert = newAlert(五子棋游戲說明image,/ elseif
3、(c =ok)2Chesses.java publicclassChessespublicfinalstaticshortNO_CHESS=publicfinalstaticshortBLACK_CHESS=publicfinalstaticshortNO_CHESS=publicfinalstaticshortBLACK_CHESS=publicfinalstaticshortWHITE_CHESS=-publicfinalstaticintBOARD_SIZE16;/ 定義常量BOARD_SIZEprivateshortchess; / privatebooleangameOver=pri
4、vateshortpublicChesses()chess=new chessType=gameOver=publicvoidreset()chessType=gameOver=/ for(inti=0;iBOARD_SIZE;i+)for(intj= 0;j 15)break;/ elseif(chessxy=chessx+iy)elsefor(inti=1; i5;i+)if(x- i=5)returntrue;/ returnprivatebooleanGame_win_2(intx,inty)intcount=returnprivatebooleanGame_win_2(intx,in
5、ty)intcount=forinti1; i5; i+) / if(y+ i 15)break;/ elseif(chessxy=chessxy+i)elseforinti1; i5; i+) / if(y- i=5)returntrue;/ returnprivatebooleanGame_win_3(intif(count=5)returntrue;/ returnprivatebooleanGame_win_3(intx,inty)intcount=/ for(inti=1; i5;i+)/ 4 if(x- i 15)break;/ elseif(chessxy=chessx -iy+
6、 i)elsefor(inti=1; i 15| y - i=5)returntrue;/ returnprivatebooleanGame_win_4(intx,inty)intcount=for(inti=1; i 15| y +i 15)break;/ elseif(chessxy=chessx+iy+i)elsefor(inti=1; i5;i+)if(x- i0| y - i 0)breakif(x- i0| y - i=5)returnreturn3Chessboard.javaimportimportimportimportimportimportimportimportimpo
7、rtpublicclassChessboardextendsCanvasimplementsCommandListenerprivateCommandexitnewpublicclassChessboardextendsCanvasimplementsCommandListenerprivateCommandexitnewCommand(退出Command.EXITprivateCommandpausenewCommand(暫停Command.ITEM,privateCommandundonewCommand(悔棋, Command.ITEM,privateCommandresetnewCom
8、mand(重玩Command.ITEM,privateCommandresumenewCommand(繼續(xù)Command.BACK,privatePointhumanPoint,privateintchessIndex=-privatebooleanprivateintx0,y0,h0,maxW,maxH,minV,x,privateImageprivateGraphicsprivateChessespublicChessboard(booleanselectBlackChess)this.selectBlackChess=x=y =maxW=maxH=if(maxWx=y =maxW=max
9、H=if(maxWmaxH)minV= elseminV= h0=(minV -16) /x0=(maxW -h0* 15) /y0=(maxH- h0 *15)/ chess=newhumanPoint=newPoint(Chesses.BOARD_SIZE4)/robotPoint=newPoint(Chesses.BOARD_SIZE4)/chessIndex=-if(selectBlackChess=false) gp= publicvoidclear(Graphicsg)g.fillRect(0,0,this.getWidth(),publicvoiddrawChessboard(G
10、raphicspublicvoidclear(Graphicsg)g.fillRect(0,0,this.getWidth(),publicvoiddrawChessboard(Graphicsg)g.setColor(0,0,for(inti=0;i16;i+)g.drawLine(x0,y0+h0* i,x0+15*h0,y0+h0* g.drawLine(x0+h0* i,y0,x0+h0* i,y0 +h0 *shortch=for(inti=0;iChesses.BOARD_SIZE;i+)for(intj= 0;j Chesses.BOARD_SIZE;j+)if(chij=Che
11、sses.BLACK_CHESS)g.setColor(0,0,g.fillRoundRect(x0+i*h0 - h0/2,y0+j *h0 -h0/h0,h0,h0,elseif(chij=Chesses.WHITE_CHESS)g.setColor(255,255,g.fillRoundRect(x0+i*h0 - h0/2,y0+j *h0 -h0/h0,h0,h0,g.setColor(255,0,g.drawRect(x*h0+x0- h0 /h0,h0,h0,g.setColor(255,0,g.drawRect(x*h0+x0- h0 /2,y* h0+y0 - h0/ 2,h
12、0,protectedvoidpaint(Graphicsg)/ / protectedvoidkeyPressed(intkeyCode)intgameKey=if(gameKey=Canvas.UP)if(y= 15)y=elseif(gameKey=Canvas.LEFT)if(x= 0)x=elseif(gameKeyif(x= 15)x=elseif(gameKey=Canvas.FIRE)booleanisHas=chess.hasChess(x,if(isHas)Imageimage=try image=catch(IOExceptione)/ 創(chuàng)建Alert Alertalne
13、w Alert(提示窗口該處已有棋子,請(qǐng)另選點(diǎn)落子image, elsechess.putChess(x,humanPointchessIndex=newPoint(x,if(chess.isGameOver()Imageimage=try imagehumanPointchessIndex=newPoint(x,if(chess.isGameOver()Imageimage=try image=catch(IOExceptione)Alertalnew Alert(本局結(jié)果本次人獲勝 elsePointp= / if(chess.isGameOver()Imageimage=try imag
14、e=catch(IOExceptione)Alertalnew Alert(本局結(jié)果本次機(jī)器獲勝catch(IOExceptione)Alertalnew Alert(本局結(jié)果本次機(jī)器獲勝 drawChessboard(gp);/ publicvoidcommandAction(Commandc,Displayabled)/ if(c=exit)elseif(c=pause)Imageimage=try image=catch(IOExceptione)Alertalnew Alert(暫停暫停中,歡迎回來! elseifAlertalnew Alert(暫停暫停中,歡迎回來! elseif(
15、c=resume)elseif(c=undo)if(chessIndex0)AlertalnewAlert(不能悔棋該步不可以悔棋 elseif(c=reset)chessIndex=-x=y =if(selectBlackChess=false)4 x=y =if(selectBlackChess=false)4 publicclassAIpublicstaticPointfindBestLocation(Chesseschess)intpower=new for(short i=0;iChesses.BOARD_SIZE;i+) for(shortj= 0;jChesses.BOARD_S
16、IZE;j+)/ 當(dāng)已有子時(shí)將該點(diǎn)的權(quán)值設(shè)為-if(chess.getChess()ij!=0)powerij=-/ elsepowerij=(short)calcPower(i,j,chess.getCurrentType(),PointbestLoc=power=return intmaxpower=return intmax=shortx=0,y=for(short i=0;iChesses.BOARD_SIZE;i+) for(shortj= 0;jmax)x=y =max=returnnewPoint(x,privatestaticintcalcPower(shortm,shortn
17、,shortcurrentType,Chesseschess)intp=intpower= 1000,85,60,45,20,15,10,5shortarrLinks=newchess.setChessFeeler(m,n,arrLinks=calcLinkCount(m,n,/ 如果m,n 是中心點(diǎn), if(m= Chesses.BOARD_SIZE/2& n=Chesses.BOARD_SIZE/2)pif(m= Chesses.BOARD_SIZE/2& n=Chesses.BOARD_SIZE/2)p+=for(short i=0;i4; i+)if(Math.abs(arrLinks
18、i)=5)p+=elseif(arrLinksi= 4)p+= elseif(arrLinksi= 3)p+= elseif(arrLinksi= 2)p+= if(currentType=Chesses.BLACK_CHESS) else arrLinks=calcLinkCount(m,n,/ for(short i=0;i4; i+)if(Math.abs(arrLinksi)=5)p+=elseif(arrLinksi= 4)p+=elseif(arrLinksi= 3)p+=elseifelseif(arrLinksi= 3)p+=elseif(arrLinksi= 2)p+=che
19、ss.setChessFeeler(m,n,(short)arrLinks=returnprivatestaticshortcalcLinkCount(shortm,shortn,shortchessmap)shortcounts=newshortflag= shortnum= / shortx=(short)(m+ inty=n+ for(;x= 0;)if(chessmapxn=chessmapmn)elseif(x= -1)else/ if(chessmapxn!=0)if(flag=2) counts0=(short)-elseif(flagif(flag=2) counts0=(sh
20、ort)-elseif(flag=1 &num =3) / 3 counts0=(short)-elsecounts0=flag=num=x=(short)(n+for(;x= 0;)/ x=(short)(n- for(;x= 0;)if(chessmapmx=chessmapmn)elseifx = -1 / elseifchessmapmx0) / flag+; if(flag=2) counts1=(short)-elseif(flag=1 &num =3) / 3 counts1=(short)-elsecounts1=flag=0;num= xshort)m1);/ forxChesses.BOARD_SIZEflag=0;num= xshort)m1);/ forxChesses.BOARD_SIZE&yChesses.BOARD_SIZE;) / if(chessmapxy=chessmapmn)else/ if(x=Chesses.BOARD_SIZE|y=Ch
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 鷹課件語文教學(xué)課件
- 特殊旅客課件教學(xué)課件
- 2024年度建設(shè)工程施工合同工期與質(zhì)量要求
- 2024年度維修保養(yǎng)服務(wù)合同
- 2024年城鄉(xiāng)供水工程特許經(jīng)營合同
- 2024年度設(shè)備采購合同:甲乙雙方在二零二四年就某設(shè)備的采購的詳細(xì)合同條款
- 2024企業(yè)人力資源管理與聘用合同詳細(xì)規(guī)定
- 2024年家長學(xué)生老師三方面協(xié)議
- 2024年國際貨物買賣合同:機(jī)械設(shè)備
- 【初中生物】觀察周邊環(huán)境中的生物+課件2024-2025學(xué)年人教版生物七年級(jí)上冊(cè)
- 辦稅服務(wù)外包投標(biāo)方案(技術(shù)標(biāo))
- 冷庫是有限空間應(yīng)急預(yù)案
- 基于PLC的機(jī)械手控制系統(tǒng)設(shè)計(jì)畢業(yè)設(shè)計(jì)
- 足軟組織感染的護(hù)理查房
- 建設(shè)項(xiàng)目竣工環(huán)境保護(hù)驗(yàn)收管理辦法
- 植物學(xué)課件:第二章 種子和幼苗
- 一日生活中幼兒自主探究行為的表現(xiàn)及支持策略研究
- 第8課 用制度體系保證人民當(dāng)家做主
- 軟件測(cè)試規(guī)范模板
- 足皮膚感染的護(hù)理課件
- 新蘇教版六年級(jí)上冊(cè)科學(xué)全冊(cè)知識(shí)點(diǎn)(精編)
評(píng)論
0/150
提交評(píng)論