当前位置:首页 » 操作系统 » 连连看算法

连连看算法

发布时间: 2022-01-08 03:57:33

A. 连连看算法

第一个:
bool isClear(int row1,int col1,int row2,int col2)
{
int row,col;
for(row=1;row

B. 我要一个用c语言做连连看(有图片),怎样生成地图,怎样实现算法。

太麻烦了,要调用Windows API 。估计一天都不一定能搞定。
用MFC .net 估计都没人帮你做。
生成地图你可以将 每种图片的数量保存好 比如 苹果用 1表示 西瓜用2 表示 ,可以弄一个链表,方便删除, 生成地图时随机一个数,到链表里取出,然后在从连表里删除。

判断的话 你可以将 地图在加大一格(不显示),然后用类似寻路算法来做。
我没实践过,你可以试试。

C. java连连看使用广度优先算法实现,求具体解释广度优先算法和代码

void bfs(TreeNode t){
Queue q = new LinkedList<TreeNode>();
q.enqueue(t);
while(!q.isEmpty && q.peek().element != null){
TreeNode temp = q.dequeue();
System.out.println(temp.element);
q.enqueue(temp.leftchild);
q.enqueue(temp.rightchild);
}
}
class TreeNode <AnyType>{
AnyType element;
TreeNode rightchild;
TreeNode leftchild;
}

D. 给个连连看算法或源码,C#,或JAV的都可以

/*
* 连连看游戏C语言源代码
*/#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <dos.h>#define true 1
#define false 0/* ---------------------全局变量------------------------------------ */
int BkGndColor=BLACK;
int BorderColor=LIGHTGRAY;
int LineColor=LIGHTBLUE;/* 消除一对方块时时候的连线颜色 */
/* Pb - ProgressBar */
int PbColor=LIGHTGREEN;
int PbY=4;
int PbHeight=4;
int PbValue; /* 进度条百分比,初始值为100.*/
long StartTime; /* 开始时间的秒数,只统计分钟,秒 */
long TotalTime; /* 游戏总共的最大秒数!,*//* BoardDatas: a small-size board */
/* Board[x][y][0] - 0:empty, 1:filled */
/* Board[x][y][1] - cell's key; */
unsigned char Board[10][10][2];
int CellSize=30;
int BoardX=20;
int BoardY=60;
int BoardWidth=10;
int BoardHeight=10;
int CellColor=WHITE;
int SelColor=BLUE; /* selCell's border rect color */
int CurColor=RED; /* curCell's border rect color */
int EraColor=CYAN; /* 用于擦除cell的颜色!*/
int PairsCount; /* how much pairs we have put on board *//* 用于存储逻辑坐标(索引) */
typedef struct _tagCELL
{
char x;
char y;
} CELL;CELL selCell,curCell;/*缓存前一个被选中的位置以及当前所处位置!*//*Scan Codes Define*/
enum KEYCODES
{
K_ESC =0x011b,
K_UP =0x4800, /* upward arrow */
K_LEFT =0x4b00,
K_DOWN =0x5000,
K_RIGHT =0x4d00,
K_SPACE =0x3920,
K_P =0x1970,
K_RETURN =0x1c0d, /* Enter */
}; /* ---------------------函数列表------------------------------------ */
void InitGame(char *bgiPath);
void PlayGame();
void QuitGame();
void InitProgressBar();
void UpdateProgressBar(int percent);
void DrawCell(int key,int x,int y,int color);
void EraseCell(int x,int y);
void DrawBorderRect(CELL *c,int color);
void DrawGameOver(char* info);
int GetKeyCode();
int FindPath(CELL *c1,CELL *c2);
/*绘制消除方块时候的连接路径!,用指定颜色!*/
void DrawPath(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int color);/* ----------------------函数实现----------------------------------- *//* ----------------------[ 核心算法 ]---------------------------------
* 先进行水平方向判断,找出两点所在的水平直线活动范围,
* 算出这两条线段在垂直方向的共同区域!!!,
* 遍历该区域判断能否在两线段间架起公垂线,能则两点连接上;
* 接着进行垂直方向判断,类同。无论两点在不在一条直线上,
* 都能使用该算法,因为两点同线只是两点作为矩形对角点的特例而已。
*//* 找到两个CELL之间的路径,成功返回true */
int FindPath(CELL *c1,CELL *c2)
{
int i,j,path,min1,max1,min2,max2,left,right,top,bottom;
/*---------------(0)判断是否点中相同块! ------------*/
if(Board[c1->x][c1->y][1] != Board[c2->x][c2->y][1])
return false;
/*---------------(1)查找水平方向公共区域!-----------*/
min1=max1=c1->x;
min2=max2=c2->x;
while(min1-1>=0 && Board[min1-1][c1->y][0]==0) min1--;
while(min2-1>=0 && Board[min2-1][c2->y][0]==0) min2--;
left=max(min1,min2); /* 左边界 */
while(max1+1<BoardWidth && Board[max1+1][c1->y][0]==0) max1++;
while(max2+1<BoardWidth && Board[max2+1][c2->y][0]==0) max2++;
right=min(max1,max2); /* 右边界 */ /* 检查两条水平线之间是否有公垂线连通!*/
/* 可以在边缘连通 */
if(left==0)
{
/* 左边缘连通 */
DrawPath(c1->x,c1->y, -1,c1->y, -1,c2->y, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, -1,c1->y, -1,c2->y, c2->x,c2->y, BkGndColor);/*插除线条!*/
return true;
}
if(right==(BoardWidth-1))
{
DrawPath(c1->x,c1->y, BoardWidth,c1->y, BoardWidth,c2->y, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, BoardWidth,c1->y, BoardWidth,c2->y, c2->x,c2->y, BkGndColor);/*插除线条!*/
return true;
} for(i=left;i<=right;i++)
{
path=0;/*统计垂直的公垂线长度!*/
for(j=min(c1->y,c2->y)+1;j<max(c1->y,c2->y);j++)
{
path+=Board[i][j][0];
if(path>0) break;
}
if(path==0)
{
DrawPath(c1->x,c1->y, i,c1->y, i,c2->y, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, i,c1->y, i,c2->y, c2->x,c2->y, BkGndColor);/*插除线条!*/
return true;
}
} /*---------------(2)查找垂直方向公共区域!-----------*/
min1=max1=c1->y;
min2=max2=c2->y;
while(min1-1>=0 && Board[c1->x][min1-1][0]==0) min1--;
while(min2-1>=0 && Board[c2->x][min2-1][0]==0) min2--;
top=max(min1,min2);
while(max1+1<BoardHeight && Board[c1->x][max1+1][0]==0) max1++;
while(max2+1<BoardHeight && Board[c2->x][max2+1][0]==0) max2++;
bottom=min(max1,max2); /* 检查两条垂直线之间是否有公垂线连通!*/
/* 可以在边缘连通 */
if(top==0)
{
/* 同在顶端消除 */
DrawPath(c1->x,c1->y, c1->x,-1, c2->x,-1, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, c1->x,-1, c2->x,-1, c2->x,c2->y, BkGndColor);/*插除线条!*/
return true;
}
if(bottom==(BoardHeight-1))
{
DrawPath(c1->x,c1->y, c1->x,BoardHeight, c2->x,BoardHeight, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, c1->x,BoardHeight, c2->x,BoardHeight, c2->x,c2->y, BkGndColor);/*插除线条!*/
return true;
} for(j=top;j<=bottom;j++)
{
path=0;/*统计水平的公垂线长度!*/
for(i=min(c1->x,c2->x)+1; i<max(c1->x,c2->x); i++)
{
path+=Board[i][j][0];
if(path>0) break;
}
if(path==0)
{
/* 水平公垂线 */
DrawPath(c1->x,c1->y, c1->x,j, c2->x,j, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, c1->x,j, c2->x,j, c2->x,c2->y, BkGndColor);/*插除线条!*/
return true;
}
} /* 到达这里说明没有任何通路 */
return false;
}
/*Get Key Code */
int GetKeyCode()
{
int key=0;
if(bioskey(1))
{
key=bioskey(0);
}
return key;
}/*绘制消除方块时候的连接路径!,用指定颜色!,坐标是CELL逻辑坐标!*/
void DrawPath(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int color)
{
setcolor(color);
moveto(BoardX+CellSize/2+CellSize*x1,BoardY+CellSize/2+CellSize*y1);
lineto(BoardX+CellSize/2+CellSize*x2,BoardY+CellSize/2+CellSize*y2);
lineto(BoardX+CellSize/2+CellSize*x3,BoardY+CellSize/2+CellSize*y3);
lineto(BoardX+CellSize/2+CellSize*x4,BoardY+CellSize/2+CellSize*y4);
}
/* congratulations info,the user has success finish the game ! */
void DrawGameOver(char* info)
{
/*计算棋盘的中心点*/
int cx=BoardX+CellSize*BoardWidth/2;
int cy=BoardY+CellSize*BoardHeight/2;
struct textsettingstype textInfos;
/*获取此前的文字信息*/
gettextsettings(&textInfos);
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL,BLUE);
/* 文字居中 */
rectangle(cx-102,cy-22,cx+102,cy+22);
floodfill(cx,cy,DARKGRAY);
rectangle(cx-100,cy-20,cx+100,cy+20);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(LIGHTBLUE);
outtextxy(cx,cy,info);
/*restore orignal text settings */
settextjustify(textInfos.horiz, textInfos.vert);
}/* draw a focus rect on the cell with the color */
/* 用制定颜色绘制一个选中的外边框 */
void DrawBorderRect(CELL *c,int color)
{
setcolor(color);
rectangle(BoardX+(c->x)*CellSize+1, BoardY+(c->y)*CellSize+1, BoardX+(c->x+1)*CellSize-2, BoardY+(c->y+1)*CellSize-2);
rectangle(BoardX+(c->x)*CellSize, BoardY+(c->y)*CellSize, BoardX+(c->x+1)*CellSize-1, BoardY+(c->y+1)*CellSize-1);
}/* 在x,y处用指定颜色绘制键为key的 CELL,key在2,3,4,5,6,7,8,9,10,11之间随机 */
void DrawCell(int key,int x,int y,int color)
{
setcolor(color);
rectangle(BoardX+x*CellSize+2, BoardY+y*CellSize+2, BoardX+(x+1)*CellSize-3, BoardY+(y+1)*CellSize-3);
setfillstyle(key, color);
floodfill(BoardX+x*CellSize+3, BoardY+y*CellSize+3,color);
}/* 擦除CELL */
void EraseCell(int x,int y)
{
setcolor(EraColor);
rectangle(BoardX+x*CellSize+2, BoardY+y*CellSize+2, BoardX+(x+1)*CellSize-3, BoardY+(y+1)*CellSize-3);
setfillstyle(SOLID_FILL, BkGndColor);
floodfill(BoardX+x*CellSize+3, BoardY+y*CellSize+3,EraColor);
setcolor(BkGndColor);
rectangle(BoardX+x*CellSize+2, BoardY+y*CellSize+2, BoardX+(x+1)*CellSize-3, BoardY+(y+1)*CellSize-3);
}
/* 初始化进度条 */
void InitProgressBar()
{
int width=CellSize*BoardWidth;
/* progress bar border rect */
setcolor(BorderColor);
rectangle(BoardX-2,PbY-2,BoardX+width+2,PbY+PbHeight+2); /* draw a value = 100% progress bar */
setcolor(PbColor);
rectangle(BoardX,PbY,BoardX+width,PbY+PbHeight);
setfillstyle(SOLID_FILL,PbColor);
floodfill(BoardX+1,PbY+1,PbColor);
}

E. 连连看的游戏,用的是什么原理算法,求指教一二

连连看核心算法如下:

#include <iostream>
using namespace std;

int board[102][102];
int nRowCount, nColCount;

bool isHorizontalLineValid(int c1, int c2, int r)
{
if(c1>c2) // 交换 C1, C2
{
c1 ^= c2 ^= c1 ^= c2;
}
for(int i=c1+1; i<=c2-1; i++)
{
if(board[r][i]!=0)
return false;
}
return true;
}

bool isVerticalLineValid(int r1, int r2, int c)
{
if(r1>r2) // 交换 r1, r2
{
r1 ^= r2 ^= r1 ^= r2;
}
for(int i=r1+1; i<=r2-1; i++)
{
if(board[i][c]!=0)
return false;
}
return true;
}

bool check(int r1, int c1, int r2, int c2)
{
// 如果该位置没有棋子或者两棋子不一致,则返回假
if(board[r1][c1]==0 || board[r2][c2]==0 || board[r1][c1]!=board[r2][c2])
return false;

// 两条水平线和一条垂直线
for(int i=0; i<=nColCount+1; i++)
{
if( (i!=c1 && board[r1][i]!=0) || (i!=c2 && board[r2][i]!=0) )
continue;
if( isHorizontalLineValid(i, c1, r1) &&
isVerticalLineValid(r1, r2, i) &&
isHorizontalLineValid(i, c2, r2))
{
board[r1][c1] = board[r2][c2] = 0;
return true;
}
}
// 两条垂直线和一条水平线
for(int i=0; i<=nRowCount+1; i++)
{
if( (i!=r1 && board[i][c1]!=0) || (i!=r2 && board[i][c2]!=0) )
continue;
if( isVerticalLineValid(i, r1, c1) &&
isHorizontalLineValid(c1, c2, i) &&
isVerticalLineValid(i, r2, c2))
{
board[r1][c1] = board[r2][c2] = 0;
return true;
}
}

return false;
}

int main(int argc, char** argv)
{
int nRound, nSuccess;
int x1, y1, x2, y2;

// 输入棋盘数据
cin >> nRowCount >> nColCount;
for(int i = 1; i <= nRowCount; ++i)
for(int j = 1; j <= nColCount; ++j)
cin >> board[i][j];

cin >> nRound;

for(int i = 0; i < nRound; ++i)
{
cin >> x1 >> y1 >> x2 >> y2;
if( check(x1, y1, x2, y2) )
cout << "Yes\n";
else
cout << "No\n";
}

system("pause");
return 0;
}

测试数据:
3 4
1 1 2 2
3 3 4 4
2 2 1 1
6
1 1 1 2
1 3 1 4
2 1 2 2
2 3 2 4
3 1 3 2
3 3 3 4

c1 ^= c2 ^= c1 ^= c2;语句中对于a^=b就相当于a=a^b,即代表a与b取位异或运算之后再把值赋给a的。楼主如果觉得还行的话请加点分的哦。

F. 求连连看源代码

连连看的代码(基本算法)加了部分注释
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
static String s="no"; //用来纪录点击按钮的信息
int x0=0,y0=0,x=0,y=0,n1=0,n2=0; //用来纪录按钮的位置信息
Frame f,f1;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10; //用比较笨的方法添加了
Button b11,b12,b13,b14,b15,b16,b17,b18; //30个按钮来实现游戏界面
Button b19,b20,b21,b22,b23,b24,b25; //可以用数组实现,这是本人
Button b26,b27,b28,b29,b30,bc; //学java时,入门的联系,所以
Button b,ba,br,bt1,bt2; //有些东西很业余!!嘻嘻
Panel p1,p2,p3;
TextField t; //用来显示一些随机信息,方法是下面的guli().
Label l;
int d[][]={ //用来和界面的按钮建立映射关系
{0,0,0,0,0,0,0},

{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}
};
public static void main(String[] args)
{

lianliankan t=new lianliankan();
t.suiji();
t.go();

}
public void actionPerformed(ActionEvent e) //再来一次按钮的响应事件。
{
int d[][]={
{0,0,0,0,0,0,0},

{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}
};
this.d=d;
suiji();
f.setVisible(false);
f1.setVisible(false);
s="no";
go();

}

public void go()//初始化界面
{
l=new Label("亲爱的玩家,");
f=new Frame("连连看");
t=new TextField();
p2=new Panel();
p1=new Panel();
p3=new Panel();
bc=new Button("退出");
br=new Button("重列");
b=new Button();
b1=new Button(String.valueOf(d[1][1]));
b2=new Button(String.valueOf(d[1][2]));
b3=new Button(String.valueOf(d[1][3]));
b4=new Button(String.valueOf(d[1][4]));
b5=new Button(String.valueOf(d[1][5]));
b6=new Button(String.valueOf(d[2][1]));
b7=new Button(String.valueOf(d[2][2]));
b8=new Button(String.valueOf(d[2][3]));
b9=new Button(String.valueOf(d[2][4]));
b10=new Button(String.valueOf(d[2][5]));
b11=new Button(String.valueOf(d[3][1]));
b12=new Button(String.valueOf(d[3][2]));
b13=new Button(String.valueOf(d[3][3]));
b14=new Button(String.valueOf(d[3][4]));
b15=new Button(String.valueOf(d[3][5]));
b16=new Button(String.valueOf(d[4][1]));
b17=new Button(String.valueOf(d[4][2]));
b18=new Button(String.valueOf(d[4][3]));
b19=new Button(String.valueOf(d[4][4]));
b20=new Button(String.valueOf(d[4][5]));
b21=new Button(String.valueOf(d[5][1]));
b22=new Button(String.valueOf(d[5][2]));
b23=new Button(String.valueOf(d[5][3]));
b24=new Button(String.valueOf(d[5][4]));
b25=new Button(String.valueOf(d[5][5]));
b26=new Button(String.valueOf(d[6][1]));
b27=new Button(String.valueOf(d[6][2]));
b28=new Button(String.valueOf(d[6][3]));
b29=new Button(String.valueOf(d[6][4]));
b30=new Button(String.valueOf(d[6][5]));
p3.setLayout(null);
p1.setSize(250,300);
p2.setSize(100,40);
p3.setSize(300,30);
t.setSize(60,30);
l.setSize(70,30);
p1.setLayout(new GridLayout(6,5));
p1.setBackground(Color.pink);
p1.setLocation(100,100);
p2.setLocation(0,400);
p3.setLocation(50,50);
t.setLocation(230,2);
l.setLocation(150,2);
bc.setLocation(0,40);
br.setLocation(0,100);
f.add(p1);
f.add(p2);
f.add(p3);
p3.add(l);
p3.add(t);
p2.add(bc);
p2.add(br);
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);
p1.add(b5);
p1.add(b6);
p1.add(b7);
p1.add(b8);
p1.add(b9);
p1.add(b10);
p1.add(b11);
p1.add(b12);
p1.add(b13);
p1.add(b14);
p1.add(b15);
p1.add(b16);
p1.add(b17);
p1.add(b18);
p1.add(b19);
p1.add(b20);
p1.add(b21);
p1.add(b22);
p1.add(b23);
p1.add(b24);
p1.add(b25);
p1.add(b26);
p1.add(b27);
p1.add(b28);
p1.add(b29);
p1.add(b30);
f.pack();
f.setBounds(280,100,500,450);
f.setResizable(false);
f.setVisible(true);
bc.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
ex();
}

});
br.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
chonglie();
}

});
b1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(1,1,b1);

}

});
b2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(1,2,b2);
}

});
b3.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{

wei(1,3,b3);

}

});
b4.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{

wei(1,4,b4);
}

});
b5.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(1,5,b5);
}
});
b6.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(2,1,b6);
}
});
b7.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(2,2,b7);
}
});
b8.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(2,3,b8);
}
});
b9.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(2,4,b9);
}
});
b10.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(2,5,b10);
}
});
b11.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(3,1,b11);
}
});
b12.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(3,2,b12);
}
});
b13.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(3,3,b13);
}
});
b14.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(3,4,b14);
}
});
b15.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(3,5,b15);
}
});
b16.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(4,1,b16);
}
});
b17.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(4,2,b17);
}
});
b18.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(4,3,b18);
}
});
b19.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(4,4,b19);
}
});
b20.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(4,5,b20);
}
});
b21.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(5,1,b21);
}
});
b22.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(5,2,b22);
}
});
b23.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(5,3,b23);
}
});
b24.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(5,4,b24);
}
});
b25.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(5,5,b25);
}
});
b26.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(6,1,b26);
}
});
b27.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(6,2,b27);
}
});
b28.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(6,3,b28);
}
});
b29.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(6,4,b29);
}
});
b30.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
wei(6,5,b30);
}
});

}

public void ex() //退出界面,可用diolog来实现有模式的类型,更加符合
{
f1=new Frame("游戏作业");
f1.setLayout(new GridLayout(1,1));
bt1=new Button("确定退出");
bt2=new Button("再来一局");
f1.add(bt1);
f1.add(bt2);
f1.pack();
f1.setBounds(400,250,90,60);
f1.setResizable(false);
f1.show();
f1.setVisible(true);
bt1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
System.exit(0);
}
});
bt2.addActionListener(this);
}

public void suiji() //产生随机数,来填充游戏界面对应的数组的各个位置
{
int m,n,k=0,k1,k2,k3;
for(m=1;m<=15;m++)
{
k1=(int)(Math.random()*25+1);
for(n=1;n<=2;n++)
{
k2=(int)(Math.random()*6+1);
k3=(int)(Math.random()*5+1);
while(d[k2][k3]!=0 && k!=30)
{
k2=(int)(Math.random()*6+1);
k3=(int)(Math.random()*5+1);
}
this.d[k2][k3]=k1;
k++;
}
}
}

public void guli() //随机信息
{
int l=0;
t.setText("");
l=(int)(Math.random()*10);
System.out.println(l);
switch(l)
{
case 1:
t.setText("好!加油!");
break;

case 3:
t.setText("你真棒!");
break;

case 5:
t.setText("加快速度!");
break;

case 6:
t.setText("不错啊!");
break;

case 8:
t.setText("加油吧!");
break;

case 9:
t.setText("够聪明!");
break;

default:
break;

}
}
public void chonglie() //重列方法
{
int save[],i,j,n=0,k2,k3,k;
int d[][]={
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0},
{0,0,0,0,0,0,0}
};
save=new int[30];
for(n=0;n<30;n++)
save[n]=0; //定义一个数组来保存当前的每个按钮位置上的信息
n=0;
for(i=0;i<=6;i++)
for(j=0;j<=5;j++)
{
if(this.d[i][j]!=0)
{
save[n]=this.d[i][j];
n++;
}
}
n=n-1;
this.d=d;
while(n>=0) //产生随机位置,放置按钮
{
k2=(int)(Math.random()*6+1);
k3=(int)(Math.random()*5+1);
while(d[k2][k3]!=0)
{
k2=(int)(Math.random()*6+1);
k3=(int)(Math.random()*5+1);
}
this.d[k2][k3]=save[n];
n--;
}
f.setVisible(false);
s="no"; //这里一定要将按钮点击信息归为初始
go();
ling();
}
public void ling() //将数组中为零的成员对应的按钮消去
{ //用按钮类型的数组实现会简化得多,
if(d[1][1]==0)
b1.setVisible(false);
if(d[1][2]==0)
b2.setVisible(false);
if(d[1][3]==0)
b3.setVisible(false);
if(d[1][4]==0)
b4.setVisible(false);
if(d[1][5]==0)
b5.setVisible(false);
if(d[2][1]==0)
b6.setVisible(false);
if(d[2][2]==0)
b7.setVisible(false);
if(d[2][3]==0)
b8.setVisible(false);
if(d[2][4]==0)
b9.setVisible(false);
if(d[2][5]==0)
b10.setVisible(false);
if(d[3][1]==0)
b11.setVisible(false);
if(d[3][2]==0)
b12.setVisible(false);
if(d[3][3]==0)
b13.setVisible(false);
if(d[3][4]==0)
b14.setVisible(false);
if(d[3][5]==0)
b15.setVisible(false);
if(d[4][1]==0)
b16.setVisible(false);
if(d[4][2]==0)
b17.setVisible(false);
if(d[4][3]==0)
b18.setVisible(false);
if(d[4][4]==0)
b19.setVisible(false);
if(d[4][5]==0)
b20.setVisible(false);
if(d[5][1]==0)
b21.setVisible(false);
if(d[5][2]==0)
b22.setVisible(false);
if(d[5][3]==0)
b23.setVisible(false);
if(d[5][4]==0)
b24.setVisible(false);
if(d[5][5]==0)
b25.setVisible(false);
if(d[6][1]==0)
b26.setVisible(false);
if(d[6][2]==0)
b27.setVisible(false);
if(d[6][3]==0)
b28.setVisible(false);
if(d[6][4]==0)
b29.setVisible(false);
if(d[6][5]==0)
b30.setVisible(false);
}

public void wei(int w1,int w2,Button bz) //判断并纪录每次点击按钮的信息
{ //当两次的按钮相同才能消去
if((s.trim()).equals("no"))
{
s=b1.getLabel();
x0=w1;
y0=w2;
n1=d[x0][y0];
b=bz;
x=w1;
y=w2;
n2=d[x][y];
ba=bz;

}
else
{
x0=x;
y0=y;
n1=d[x0][y0];
b=ba;
x=w1;
y=w2;
n2=d[x][y];
ba=bz;
if(n1==n2 && ba!=b)
{
xiao();
}
}
}

public void xiao() //这里是整个游戏最重要的部分,就是判断两个按钮在信息
{ //相同的情况下能不能消去。仔细分析,不一条条注释
int i=0, j=0,n=0,k=0;
if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))) //相邻的情况
{
ba.setVisible(false);
b.setVisible(false);
guli();
s="no";
d[x0][y0]=0;
d[x][y]=0;
}
else
{
for (j=0;j<7;j++ ) //两个按钮按行分析,看能否消去
{
if (d[x0][j]==0)
{
if (y>j)
{

for (i=y-1;i>=j;i-- )
{
if (d[x][i]!=0)
{
k=0;
break;
}
else
{
k=1;
}
}
if (k==1)
{
if (y0>j)
{
for (i=y0-1;i>=j ;i-- )
{
if (d[x0][i]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
if (y0<j)
{
for (i=y0+1;i<=j ;i++)
{
if (d[x0][i]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
}
}
if (y<j)
{

for (i=y+1;i<=j ;i++ )
{

if (d[x][i]!=0)
{
k=0;
break;
}
else
{
k=1;
}
}
if (k==1)
{
if (y0>j)
{
for (i=y0-1;i>=j ;i-- )
{
if (d[x0][i]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
if (y0<j)
{
for (i=y0+1;i<=j ;i++)
{
if (d[x0][i]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
}
}
if (y==j )
{
if (y0>j)
{
for (i=y0-1;i>=j ;i-- )
{

if (d[x0][i]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
if (y0<j)
{
for (i=y0+1;i<=j ;i++)
{
if (d[x0][i]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
}
}
if (k==2)
{ if (x0==x)
{
b.setVisible(false);
ba.setVisible(false);
guli();
s="no";
k=0;
d[x0][y0]=0;
d[x][y]=0;
}
if (x0<x)
{
for (n=x0;n<=x-1;n++ )
{
if (d[n][j]!=0)
{
k=0;
break;
}
if(d[n][j]==0 && n==x-1)
{
b.setVisible(false);
ba.setVisible(false);
guli();
s="no";
k=0;
d[x0][y0]=0;
d[x][y]=0;
}
}
}
if (x0>x)
{
for (n=x0;n>=x+1 ;n-- )
{
if (d[n][j]!=0)
{
k=0;
break;
}
if(d[n][j]==0 && n==x+1)
{
b.setVisible(false);
ba.setVisible(false);
guli();
s="no";
k=0;
d[x0][y0]=0;
d[x][y]=0;

}
}
}
}
}

for (i=0;i<8;i++ ) //按列分析,看能不能消去
{
if (d[i][y0]==0)
{
if (x>i)
{

for (j=x-1;j>=i ;j-- )
{
if (d[j][y]!=0)
{
k=0;
break;
}
else
{
k=1;
}
}

if (k==1)
{
if (x0>i)
{
for (j=x0-1;j>=i ;j-- )
{
if (d[j][y0]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
if (x0<i)
{
for (j=x0+1;j<=i;j++ )
{
if (d[j][y0]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
}
}
if (x<i)
{

for (j=x+1;j<=i;j++ )
{
if (d[j][y]!=0)
{
k=0;
break;
}
else
{
k=1;
}
}
if (k==1)
{
if (x0>i)
{
for (j=x0-1;j>=i ;j-- )
{
if (d[j][y0]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
if (x0<i)
{
for (j=x0+1;j<=i ;j++ )
{
if (d[j][y0]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
}
}
if (x==i)
{

if (x0>i)
{
for (j=x0-1;j>=i ;j-- )
{
if (d[j][y0]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}
if (x0<i)
{
for (j=x0+1;j<=i ;j++ )
{
if (d[j][y0]!=0)
{
k=0;
break;
}
else
{
k=2;
}
}
}

}
}
if (k==2)
{
if (y0==y)
{
b.setVisible(false);
ba.setVisible(false);
guli();
s="no";
k=0;
d[x0][y0]=0;
d[x][y]=0;

}
if (y0<y)
{
for (n=y0;n<=y-1 ;n++ )
{
if (d[i][n]!=0)
{
k=0;
break;
}
if(d[i][n]==0 && n==y-1)
{
b.setVisible(false);
ba.setVisible(false);
guli();
s="no";
k=0;
d[x0][y0]=0;
d[x][y]=0;

}
}
}
if (y0>y)
{
for (n=y0;n>=y+1 ;n--)
{
if (d[i][n]!=0)
{
k=0;
break;
}
if(d[i][n]==0 && n==y+1)
{
b.setVisible(false);
ba.setVisible(false);
guli();
s="no";
k=0;
d[x0][y0]=0;
d[x][y]=0;

}
}
}
}
}

}
}
}

G. QQ连连看的积分是怎么算的

积分貌似根据你的连击次数和游戏人数来确定的,具体我也不知道啊。有空咱俩玩玩

H. 连连看中无数个折点相连的算法是怎样的

无数个折点的问题其实就是一个迷宫探路的问题,可以用一个栈或者队列来实现。

以栈为例,这个其实是深度优先的查找,设每次只走一格
0)把起点放入栈中;
1)从栈顶取一个元素(如果栈已经空,说明不通,是死路);
2)看该元素的下一步元素是否有终点,如果有,找到通路,循环结束;否则把该元素的下一步每一个可能走的格放入栈中;
3)不断重复1-2。

I. 求一连连看算法 C 语言

第一个:
bool isClear(int row1,int col1,int row2,int col2)
{
int row,col;
for(row=1;row<=ROW;row++)
if( check_point(row,col1) && check_point(row,col2) )
if( check_col(col1,row1,row) && check_row(row,col1,col2)
&& check_col(col2,row2,row) )
return true;
for( col=1;col<COL;col++)
if( check_point(row1,col) && check_point(row2,col) )
if( check_row(row1,col1,col) && check_col(col,row1,row2)
&& check_row(row2,col2,col) )
return true;
return false;
}
第二个:回溯算法
bool ClearAll()
{
int row1,col1,row2,col2;
for( row1=1;row1<ROW;row1++)
for( col1=1;col1<COL;col1++)
if( A[row1][co1]!=0 )
for( row2=row1;row2<ROW;row2++)
for( col2=1;col2<COL;col2++)
if(row2>row1 || col2>col1)
if( A[row2][col2]==A[row1][col1]
&& isClear(row1,col1,row2,col2) )
{
SaveWay();
Delete(row1,col1,row2,col2);
if( ClearAll() )
return true;
else
Load();
}
return false;
}
第三个:改写下Delete/Load函数就可以了,我就不贴出来了
=================================================
含有很多简单的函数没写,不懂再问我吧

J. 高分求多层连连看的算法

我也想要,顶一个

热点内容
海康威视存储卡质量如何 发布:2024-09-19 08:55:35 浏览:939
python3默认安装路径 发布:2024-09-19 08:50:22 浏览:516
环卫视频拍摄脚本 发布:2024-09-19 08:35:44 浏览:418
sqlserveronlinux 发布:2024-09-19 08:16:54 浏览:256
编程常数 发布:2024-09-19 08:06:36 浏览:952
甘肃高性能边缘计算服务器云空间 发布:2024-09-19 08:06:26 浏览:162
win7家庭版ftp 发布:2024-09-19 07:59:06 浏览:717
数据库的优化都有哪些方法 发布:2024-09-19 07:44:43 浏览:269
知乎华为编译器有用吗 发布:2024-09-19 07:32:20 浏览:618
访问虚拟机磁盘 发布:2024-09-19 07:28:13 浏览:670