体育资讯网

您现在的位置是:首页 > 分类12 > 正文

分类12

c连连看游戏辅助源码(c#连连看游戏源代码)

hacker2022-07-10 01:37:19分类1255
本文目录一览:1、求c语言的连连看源程序2、求连连看源代码

本文目录一览:

求c语言的连连看源程序

参考:

;vw=allssid=from=bd_page_type=1uid=D707A757C67E11B4F7ACD4D0D2C9C212pu=rc@1,pic@on,sl@1,pw@1000,sz@224_220,pd@1,fz@2,lp@0,tpl@color,st=1wk=rdmaxpage=6pos=all

以下是部分代码:

/*

* 连连看游戏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+1BoardWidth Board[max1+1][c1-y][0]==0) max1++;

while(max2+1BoardWidth 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;jmax(c1-y,c2-y);j++)

{

path+=Board[i][j][0];

if(path0) 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+1BoardHeight Board[c1-x][max1+1][0]==0) max1++;

while(max2+1BoardHeight 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;

}

求连连看源代码

连连看的代码(基本算法)加了部分注释

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;n30;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;j7;j++ ) //两个按钮按行分析,看能否消去

{

if (d[x0][j]==0)

{

if (yj)

{

for (i=y-1;i=j;i-- )

{

if (d[x][i]!=0)

{

k=0;

break;

}

else

{

k=1;

}

}

if (k==1)

{

if (y0j)

{

for (i=y0-1;i=j ;i-- )

{

if (d[x0][i]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

if (y0j)

{

for (i=y0+1;i=j ;i++)

{

if (d[x0][i]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

}

}

if (yj)

{

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

{

if (d[x][i]!=0)

{

k=0;

break;

}

else

{

k=1;

}

}

if (k==1)

{

if (y0j)

{

for (i=y0-1;i=j ;i-- )

{

if (d[x0][i]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

if (y0j)

{

for (i=y0+1;i=j ;i++)

{

if (d[x0][i]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

}

}

if (y==j )

{

if (y0j)

{

for (i=y0-1;i=j ;i-- )

{

if (d[x0][i]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

if (y0j)

{

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 (x0x)

{

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 (x0x)

{

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;i8;i++ ) //按列分析,看能不能消去

{

if (d[i][y0]==0)

{

if (xi)

{

for (j=x-1;j=i ;j-- )

{

if (d[j][y]!=0)

{

k=0;

break;

}

else

{

k=1;

}

}

if (k==1)

{

if (x0i)

{

for (j=x0-1;j=i ;j-- )

{

if (d[j][y0]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

if (x0i)

{

for (j=x0+1;j=i;j++ )

{

if (d[j][y0]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

}

}

if (xi)

{

for (j=x+1;j=i;j++ )

{

if (d[j][y]!=0)

{

k=0;

break;

}

else

{

k=1;

}

}

if (k==1)

{

if (x0i)

{

for (j=x0-1;j=i ;j-- )

{

if (d[j][y0]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

if (x0i)

{

for (j=x0+1;j=i ;j++ )

{

if (d[j][y0]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

}

}

if (x==i)

{

if (x0i)

{

for (j=x0-1;j=i ;j-- )

{

if (d[j][y0]!=0)

{

k=0;

break;

}

else

{

k=2;

}

}

}

if (x0i)

{

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 (y0y)

{

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 (y0y)

{

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;

}

}

}

}

}

}

}

}

连连看c语言代码 不要图片

#include stdio.h

#include stdlib.h

#include time.h

#include conio.h

void init();

void near1(int a,int b,int a1,int b1);

void print();

int exit();

char chessman[10][10];

void main()

{

int op;

int row,line;

int row2,line2;

init();

do

{

print();

printf("options:\n");

printf("\t1.select\n");

printf("\t2.restart\n");

printf("\t3.sort\n");

printf("\t4.exit\n");

scanf("%d",op);

if(op==1)

{

printf("输入第一个:");

scanf("%d %d",line,row);

printf("输入第二个:");

scanf("%d %d",line2,row2);

if(chessman[line][row]!=chessman[line2][row2])

{

printf("两数不相同!\n");

}

else if(line==line2row==row2)

{

printf("错误输入!!!\n");

}

else if(line=line2)

{

near1(line,row,line2,row2);

}

else

{

near1(line2,row2,line,row);

}

}

if(op==2)

{

}

}while(exit());

system("pause");

printf("\n\n\n\t\t恭喜您,您胜利了!\n");

}

void init()

{

int i,j;

int a[8]={0};

srand(time(NULL));

for(i=1;i8;i++)

for(j=1;j9;j++)

{

chessman[i][j]=rand()%8+65;

if(chessman[i][j]==65) a[0]++;

if(chessman[i][j]==66) a[1]++;

if(chessman[i][j]==67) a[2]++;

if(chessman[i][j]==68) a[3]++;

if(chessman[i][j]==69) a[4]++;

if(chessman[i][j]==70) a[5]++;

if(chessman[i][j]==71) a[6]++;

if(chessman[i][j]==72) a[7]++;

}

for(i=0;i8;i++)

{

if(a[i]%2!=0)

chessman[8][i+1]=i+65;

else

chessman[8][i+1]=73;

}

}

void print()

{

int i,j;

system("cls");

printf("\t 1 2 3 4 5 6 7 8 \n");

for(i=0;i10;i++)

{

printf("\t\n\t");

for(j=0;j10;j++)

{

printf("%4c",chessman[i][j]);

if(j==9i!=0i!=9)

printf("\t%d",i);

if(chessman[i][j]==0)

printf(" ");

}

}

printf("\n\n\n\n");

}

int exit()

{

int i,j;

for(i=0;i10;i++)

{

for(j=0;j10;j++)

if(chessman[i][j]!=0)

return 1;

}

return 0;

}

void near1(int a,int b,int a1,int b1)

{

int arow[2];

int aline[2];

int brow[2];

int bline[2];

int start=0,end=0;

int i,j,n;

for(i=0;i2;i++)

{

arow[i]=a;

brow[i]=a1;

aline[i]=b;

bline[i]=b1;

}

for(i=a+1;i10;i++)

{

if(chessman[i][b]==0)

arow[1]=i;

else

break;

}

for(i=a-1;i=0;i--)

{

if(chessman[i][b]==0)

arow[0]=i;

else

break;

}

for(i=a1+1;i10;i++)

{

if(chessman[i][b1]==0)

brow[1]=i;

else

break;

}

for(i=a1-1;i=0;i--)

{

if(chessman[i][b1]==0)

brow[0]=i;

else

break;

}

for(i=b+1;i10;i++)

{

if(chessman[a][i]==0)

aline[1]=i;

else

break;

}

for(i=b-1;i=0;i--)

{

if(chessman[a][i]==0)

aline[0]=i;

else

break;

}

for(i=b1+1;i10;i++)

{

if(chessman[a1][i]==0)

bline[1]=i;

else

break;

}

for(i=b1-1;i=0;i--)

{

if(chessman[a1][i]==0)

bline[0]=i;

else

break;

}

if(brow[0]=arow[0])

start=brow[0];

else

start=arow[0];

if(brow[1]=arow[1])

end=brow[1];

else

end=arow[1];

for(;start=end;start++)

{

if(bb1)

{

j=b;

i=b1;

}

else

{

j=b1;

i=b;

}

for(n=0;ji;j++)

{

if(chessman[j]==0)

n++;

else

break;

}

if((n==b-b1)(n0))

chessman[a][b]=chessman[a1][b1]=0;

if((n==b1-b)(n0))

chessman[a][b]=chessman[a1][b1]=0;

}

if(aline[0]=bline[0])

start=aline[0];

else

start=bline[0];

if(aline[1]bline[1])

end=aline[1];

else

end=bline[1];

for(i=start;i=end;i++)

{

for(j=a,n=0;ja1;j++)

{

if(chessman[j][i]==0)

n++;

else

break;

}

if(n==a1-an0)

{

chessman[a][b]=chessman[a1][b1]=0;

break;

}

}

if(a==a1)

{

if((aline[1]=b1)||(aline[0]=b1))

chessman[a][b]=chessman[a1][b1]=0;

}

if(b==b1)

{

if(arow[1]=a1)

chessman[a][b]=chessman[a1][b1]=0;

}

}

求任何可在VC/C++环境下运行的连连看游戏完整源代码文件 谢谢了。。

#include stdio.h

#include conio.h

#include windows.h

#include time.h

#define Height 25 //迷宫c连连看游戏辅助源码的高度,必须为奇数

#define Width 25 //迷宫c连连看游戏辅助源码的宽度,必须为奇数

#define Wall 1

#define Road 0

#define Start 2

#define End 3

#define Esc 5

#define Up 1

#define Down 2

#define Left 3

#define Right 4

int map[Height+2][Width+2];

void gotoxy(int x,int y) //移动坐标

{

COORD coord;

coord.X=x;

coord.Y=y;

SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );

}

void hidden()//隐藏光标

{

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_CURSOR_INFO cci;

GetConsoleCursorInfo(hOut,cci);

cci.bVisible=0;//赋1为显示,赋0为隐藏

SetConsoleCursorInfo(hOut,cci);

}

void create(int x,int y) //随机生成迷

{

int c[4][2]={0,1,1,0,0,-1,-1,0}; //四个方向

int i,j,t;

//将方向打乱

for(i=0;i4;i++)

{

j=rand()%4;

t=c[i][0];c[i][0]=c[j][0];c[j][0]=t;

t=c[i][1];c[i][1]=c[j][1];c[j][1]=t;

}

map[x][y]=Road;

for(i=0;i4;i++)

if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall)

{

map[x+c[i][0]][y+c[i][1]]=Road;

create(x+2*c[i][0],y+2*c[i][1]);

}

}

int get_key() //接收按键

{

char c;

while(c=getch())

{

if(c==27) return Esc; //Esc

if(c!=-32)continue;

c=getch();

if(c==72) return Up; //上

if(c==80) return Down; //下

if(c==75) return Left; //左

if(c==77) return Right; //右

}

return 0;

}

void paint(int x,int y) //画迷宫

{

gotoxy(2*y-2,x-1);

switch(map[x][y])

{

case Start:

printf("入");break; //画入口

case End:

printf("出");break; //画出口

case Wall:

printf("▇");break; //画墙

case Road:

printf(" ");break; //画路

}

}

void game()

{

int x=2,y=1; //玩家当前位置,刚开始在入口处

int c; //用来接收按键

while(1)

{

gotoxy(2*y-2,x-1);

printf("●"); //画出玩家当前位置

if(map[x][y]==End) //判断是否到达出口

{

gotoxy(30,24);

printf("到达终点,按任意键结束");

getch();

break;

}

c=get_key();

if(c==Esc)

{

gotoxy(0,24);

break;

}

switch(c)

{

case Up: //向上走

if(map[x-1][y]!=Wall)

{

paint(x,y);

x--;

}

break;

case Down: //向下走

if(map[x+1][y]!=Wall)

{

paint(x,y);

x++;

}

break;

case Left: //向左走

if(map[x][y-1]!=Wall)

{

paint(x,y);

y--;

}

break;

case Right: //向右走

if(map[x][y+1]!=Wall)

{

paint(x,y);

y++;

}

break;

}

}

}

int main()

{

int i,j;

srand((unsigned)time(NULL)); //初始化随即种子

hidden(); //隐藏光标

for(i=0;i=Height+1;i++)

for(j=0;j=Width+1;j++)

if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫

map[i][j]=Road;

else map[i][j]=Wall;

create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //从随机一个点开始生成迷宫,该点行列都为偶数

for(i=0;i=Height+1;i++) //边界处理

{

map[i][0]=Wall;

map[i][Width+1]=Wall;

}

for(j=0;j=Width+1;j++) //边界处理

{

map[0][j]=Wall;

map[Height+1][j]=Wall;

}

map[2][1]=Start; //给定入口

map[Height-1][Width]=End; //给定出口

for(i=1;i=Height;i++)

for(j=1;j=Width;j++) //画出迷宫

paint(i,j);

game(); //开始游戏

getch();

return 0;

}

发表评论

评论列表

  • 慵吋清晓(2022-07-10 08:37:16)回复取消回复

    int i,j; system("cls"); printf("\t 1 2 3 4 5 6 7 8 \n"); for(i=0;i10;i++) {