




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第基于Java實現(xiàn)連連看游戲的示例代碼ArrayListIntegernumbers=newArrayListInteger//鏈表
for(inti=0;iKinds;i++){
numbers.add(i+1);//加到列表尾部
numbers.add(i+1);
}//每一次重新布局的時候,能保證一定有前幾種難度中的圖片類型
Randomrandom=newRandom();
inttemp=0;
for(inti=0;i32-Kinds;i++){
temp=random.nextInt(Kinds)+1;//0~kinds-1之間的隨機數(shù)在加1
numbers.add(temp);
numbers.add(temp);
Collections.shuffle(numbers);//隨機打亂原來的順序
map=newint[8][8];
temp=0;
for(inti=0;ii++){
for(intj=0;jj++){
//JOptionPane.showMessageDialog(null,numbers.get(temp));
map[i][j]=numbers.get(temp++).intValue();//get方法返回第i個元素,intvalue返回int類型
publicvoiditemStateChanged(ItemEvente){
//TODO自動生成的方法存根
if(e.getSource()==difficultChoice){
Stringselected=difficultChoice.getSelectedItem();
if(selected=="簡單"){
Kinds=4;
newGame();
repaint();
}elseif(selected=="中等"){
Kinds=8;
newGame();
repaint();
}elseif(selected=="困難"){
Kinds=12;
newGame();
repaint();
}elseif(selected=="變態(tài)"){
Kinds=15;
newGame();
repaint();
publicvoidactionPerformed(ActionEvente){
//TODO自動生成的方法存根
if(ld.getTimes()56){
for(inti=0;ii++){
for(intj=0;jj++){
BlockButton[j][i].setEnabled(false);
if(e.getSource()==reLoad){
chongzai();
reLoad.setEnabled(false);
if(e.getSource()==newgameButton){
newGame();
reLoad.setEnabled(true);
for(inti=0;ii++){
for(intj=0;jj++){
if(e.getSource()==BlockButton[j][i]){
clicktimes++;//點擊的次數(shù)
lineStart.move(i,j);
if(clicktimes%2==1){
coordinatex1=i;
coordinatey1=j;
BlockButton[coordinatey1][coordinatex1].setEnabled(false);
BlockButton[coordinatey][coordinatex].setEnabled(true);
//BlockButton[j][i].setEnabled(false);
if(clicktimes%2==0){
coordinatex=i;
coordinatey=j;
BlockButton[coordinatey][coordinatex].setEnabled(false);
BlockButton[coordinatey1][coordinatex1].setEnabled(true);
this.requestFocus();
clearBlock();
*for(inti=0;ii++){for(intj=0;jj++){
*BlockButton[j][i].setEnabled(true);}
repaint();
//--------------------------------------------------------------------------
//判斷在一列之內(nèi)兩圖片之間是否全部是空白或直接相鄰
privatebooleancontainsAllOrNoneZeroInColumn(intposX1,intposY1,
intposX2,intposY2){
//直接相連,因而不包含空白
if(Math.abs(posY1-posY2)==0){
returntrue;
inta=posY1posY2posY1:posY2;
intb=posY1posY2posY2:posY1;//y值:a小b大
for(intj=a+1;jj++){
if(map[posX1][j]!=0){
returnfalse;
returntrue;
//判斷在一行之內(nèi)兩圖片之間是否全部是空白或直接相鄰
privatebooleancontainsAllOrNoneZeroInRow(intposX1,intposY1,
intposX2,intposY2){
//直接相連,因而不包含空白
if(Math.abs(posX1-posX2)==0){
returntrue;
inta=posX1posX2posX1:posX2;
intb=posX1posX2posX2:posX1;
for(inti=a+1;ii++){
if(map[i][posY1]!=0){
returnfalse;
returntrue;
//是否可以一直線相連
privatebooleanisLinkByOneLine(intposX1,intposY1,intposX2,
intposY2){
if(posX1!=posX2posY1!=posY2){
returnfalse;
if(posX1==posX2){
if(containsAllOrNoneZeroInColumn(posX1,posY1,posX2,posY2)){
returntrue;
if(posY1==posY2){
if(containsAllOrNoneZeroInRow(posX1,posY1,posX2,posY2)){
returntrue;
returnfalse;
//是否可以兩直線相連
privatebooleanisLinkByTwoLines(intposX1,intposY1,intposX2,
intposY2){
if(posX1!=posX2posY1!=posY2){
//x1,y1tox2,y1tox2,y2
if(containsAllOrNoneZeroInRow(posX1,posY1,posX2,posY1)
map[posX2][posY1]==0
containsAllOrNoneZeroInColumn(posX2,posY1,posX2,
posY2)){
returntrue;
//x1,y1tox1,y2tox2,y2
if(containsAllOrNoneZeroInColumn(posX1,posY1,posX1,posY2)
map[posX1][posY2]==0
containsAllOrNoneZeroInRow(posX1,posY2,posX2,
posY2)){
returntrue;
returnfalse;
//是否可以三直線相連
privatebooleanisLinkByThreeLines(intposX1,intposY1,intposX2,
intposY2){
if(isOnSameEdge(posX1,posY1,posX2,posY2)){
returntrue;
if(isOnThreeLinesLikeArc(posX1,posY1,posX2,posY2)){
returntrue;
if(isOnThreeLinesLikeZigzag(posX1,posY1,posX2,posY2)){
returntrue;
returnfalse;
//是否可以三直線相連,似U形
privatebooleanisOnThreeLinesLikeArc(intposX1,intposY1,intposX2,
intposY2){
if(isOnUpArc(posX1,posY1,posX2,posY2)){
returntrue;
if(isOnDownArc(posX1,posY1,posX2,posY2)){
returntrue;
if(isOnLeftArc(posX1,posY1,posX2,posY2)){
returntrue;
if(isOnRightArc(posX1,posY1,posX2,posY2)){
returntrue;
returnfalse;
//∪
privatebooleanisOnUpArc(intposX1,intposY1,intposX2,intposY2){
//Y--0
intlessY=posY1posY2posY1:posY2;//找小y
for(intj=lessY-1;jj--){
if(containsAllOrNoneZeroInRow(posX1,j,posX2,j)
containsAllOrNoneZeroInColumn(posX1,posY1,posX1,j)
containsAllOrNoneZeroInColumn(posX2,posY2,posX2,j)
map[posX1][j]==0map[posX2][j]==0){
returntrue;
if(isOnSameEdge(posX1,0,posX2,0)
containsAllOrNoneZeroInColumn(posX1,posY1,posX1,0)
containsAllOrNoneZeroInColumn(posX2,posY2,posX2,0)
(map[posX1][0]==0map[posX2][0]==0
||map[posX1][0]==0
map[posX2][0]==map[posX2][posY2]||map[posX1][0]==map[posX1][posY1]
map[posX2][0]==0)){
returntrue;
returnfalse;
//∩
privatebooleanisOnDownArc(intposX1,intposY1,intposX2,intposY2){
intmoreY=posY1posY2posY2:posY1;
for(intj=moreY+1;j=8-1;j++){
if(containsAllOrNoneZeroInRow(posX1,j,posX2,j)
containsAllOrNoneZeroInColumn(posX1,posY1,posX1,j)
containsAllOrNoneZeroInColumn(posX2,posY2,posX2,j)
map[posX1][j]==0map[posX2][j]==0){
returntrue;
if(isOnSameEdge(posX1,8-1,posX2,8-1)
containsAllOrNoneZeroInColumn(posX1,posY1,posX1,8-1)
containsAllOrNoneZeroInColumn(posX2,posY2,posX2,8-1)
(map[posX1][8-1]==0map[posX2][8-1]==0
||map[posX1][8-1]==map[posX1][posY1]
map[posX2][8-1]==0||map[posX1][8-1]==0
map[posX2][8-1]==map[posX2][posY2])){
returntrue;
returnfalse;
//﹚
privatebooleanisOnLeftArc(intposX1,intposY1,intposX2,intposY2){
intlessX=posX1posX2posX1:posX2;
for(inti=lessX-1;ii--){
if(containsAllOrNoneZeroInColumn(i,posY1,i,posY2)
containsAllOrNoneZeroInRow(i,posY1,posX1,posY1)
containsAllOrNoneZeroInRow(i,posY2,posX2,posY2)
map[i][posY1]==0map[i][posY2]==0){
returntrue;
if(isOnSameEdge(0,posY1,0,posY2)
containsAllOrNoneZeroInRow(0,posY1,posX1,posY1)
containsAllOrNoneZeroInRow(0,posY2,posX2,posY2)
(map[0][posY1]==0map[0][posY2]==0
||map[0][posY1]==map[posX1][posY1]
map[0][posY2]==0||map[0][posY1]==0
map[0][posY2]==map[posX2][posY2])){
returntrue;
returnfalse;
//(
privatebooleanisOnRightArc(intposX1,intposY1,intposX2,intposY2){
intmoreX=posX1posX2posX2:posX1;
for(inti=moreX+1;i=8-1;i++){
if(containsAllOrNoneZeroInColumn(i,posY1,i,posY2)
containsAllOrNoneZeroInRow(i,posY1,posX1,posY1)
containsAllOrNoneZeroInRow(i,posY2,posX2,posY2)
map[i][posY1]==0map[i][posY2]==0){
returntrue;
if(isOnSameEdge(8-1,posY1,8-1,posY2)
containsAllOrNoneZeroInRow(posX1,posY1,8-1,posY1)
containsAllOrNoneZeroInRow(posX2,posY2,8-1,posY2)
(map[8-1][posY1]==0map[8-1][posY2]==0
||map[8-1][posY1]==map[posX1][posY1]
map[8-1][posY2]==0||map[8-1][posY1]==0
map[8-1][posY2]==map[posX2][posY2])){
returntrue;
returnfalse;
//是否可以三直線相連,似之字形N
privatebooleanisOnThreeLinesLikeZigzag(intposX1,intposY1,
intposX2,intposY2){
if(isOnZigzagWith1Row2Cols(posX1,posY1,posX2,posY2)){
returntrue;
if(isOnZigzagWith2Rows1Col(posX1,posY1,posX2,posY2)){
returntrue;
returnfalse;
//是否可以三直線相連,似之字形,兩行一列Z
privatebooleanisOnZigzagWith2Rows1Col(intposX1,intposY1,
intposX2,intposY2){
intmoreX=posX1posX2posX2:posX1;
intlessX=posX1posX2posX1:posX2;
for(inti=lessX+1;imoreX;i++){
if(containsAllOrNoneZeroInColumn(i,posY1,i,posY2)
containsAllOrNoneZeroInRow(i,posY1,posX1,posY1)
containsAllOrNoneZeroInRow(i,posY2,posX2,posY2)
map[i][posY1]==0map[i][posY2]==0){
returntrue;
returnfalse;
//是否可以三直線相連,似之字形,一行兩列
privatebooleanisOnZigzagWith1Row2Cols(intposX1,intposY1,
intposX2,intposY2){
intmoreY=posY1posY2posY2:posY1;
intlessY=posY1posY2posY1:posY2;
for(intj=lessY+1;jmoreY;j++){
if(containsAllOrNoneZeroInRow(posX1,j,posX2,j)
containsAllOrNoneZeroInColumn(posX1,posY1,posX1,j)
containsAllOrNoneZeroInColumn(posX2,posY2,posX2,j)
map[posX1][j]==0map[posX2][j]==0){
returntrue;
returnfalse;
//是否處于游戲區(qū)域的4條邊的同一邊上
privatebooleanisOnSameEdge(intposX1,intposY1,intposX2,intposY2){
if((posY1==posY2posY2==0)
||(posY1==posY2posY2==8-1)
||(posX1==posX2posX2==0)
||(posX1==posX2posX2==8-1)){
returntrue;
returnfalse;
//--------------------------------------------------------------------------
publicbooleanifcanTouch(intposX1,intposY1,intposX2,intposY2){
if(isLinkByOneLine(posX1,posY1,posX2,posY2)){
returntrue;
//是否可以兩直線相連
if(isLinkByTwoLines(posX1,posY1,posX2,posY2)){
returntrue;
//是否可以三直線相連
if(isLinkByThreeLines(posX1,posY1,posX2,posY2)){
returntrue;
returnfalse;
publicvoidclearBlock(){
if(clicktimes=2){
if(map[coordinatey1][coordinatex1]==map[coordinatey][coordinatex]
!((coordinatex1==coordinatex)(coordinatey1==coordinatey))){
if(ifcanTouch(coordinatey1,coordinatex1,coordinatey,
coordinatex)){
if(map[coordinatey1][coordinatex1]0)
score=score+10;
map[coordinatey1][coordinatex1]=0;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)療設(shè)備質(zhì)量管理體系建設(shè)探討
- 區(qū)款鏈技術(shù)助力企業(yè)實現(xiàn)辦公自動化
- 鄉(xiāng)下耕地出售合同范例
- 噯氣的臨床護理
- 廈門市2025 屆高三畢業(yè)班第四次質(zhì)量檢測-英語+答案
- 醫(yī)療數(shù)字化與區(qū)塊鏈數(shù)字身份認證的協(xié)同發(fā)展
- 小學(xué)社團活動總結(jié)模版
- 醫(yī)療空間中的綠色療愈效果探索
- 醫(yī)療服務(wù)流程優(yōu)化對提高患者滿意度的影響研究
- 光伏公司租賃合同范例
- 常用個人土地承包合同
- 【鍍鉻廠污水處理設(shè)計13000字(論文)】
- 2024年注冊安全工程師考試題庫及參考答案(完整版)
- 眼的解剖結(jié)構(gòu)與生理功能課件
- DL-T 572-2021電力變壓器運行規(guī)程-PDF解密
- 2023-2024學(xué)年人教版數(shù)學(xué)八年級下冊期中訓(xùn)練卷
- 《17 他們那時候多有趣啊》公開課一等獎創(chuàng)新教學(xué)設(shè)計及反思
- 2023屆高三物理一輪復(fù)習(xí)89熱學(xué)中的變質(zhì)量問題(解析版)
- 人教版 美術(shù) 三年級下冊全冊表格式教案教學(xué)設(shè)計
- 醫(yī)院6s管理成果匯報護理課件
- 2021年全國高中數(shù)學(xué)聯(lián)賽浙江賽區(qū)初賽試題
評論
0/150
提交評論