❶ 如何用c语言编写连连看小游戏
我看没人来回答来顶你,希望哥们如果还没人分给我thanks
❷ 急需一个用C语言编写的 连连看游戏 代码啊,需要简易一点的,适合刚入门新手看懂的
你这10财富也太少了,这种范式代码很多好吧 自己网络下 一搜一大堆
❸ 谁能帮忙写一个c语言连连看游戏,要4x4的,功能最简单的就可以!但是要实现连连看应该有的功能
刚写的,新鲜出炉:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#defineMAPSIZE4
#defineMAXLINESIZE60
//typedefenum{false,true}bool;
typedefstruct{
intx,y;
}Point;
constcharpictureTable[]={"ABCEDFGHI"};
booljudgeLine(char**MP,Point*start,Point*end){
inti;
if(start->x==end->x){
if(start->y>end->y){
for(i=start->y-1;i>end->y;i--)
if(MP[start->x][i]!=0)
returnfalse;
returntrue;
}
else{
for(i=start->y+1;i<end->y;i++)
if(MP[start->x][i]!=0)
returnfalse;
returntrue;
}
}
elseif(start->y==end->y){
if(start->x>end->x){
for(i=start->x-1;i>end->x;i--)
if(MP[i][start->y]!=0)
returnfalse;
returntrue;
}
else{
for(i=start->x+1;i<end->x;i++)
if(MP[i][start->y]!=0)
returnfalse;
returntrue;
}
}
returnfalse;
}
booljudgeTwoLines(char**MP,Point*start,Point*end,Point*mid){
Pointp1,p2;
mid->x=-1;
mid->y=-1;
if(judgeLine(MP,start,end)==true)returntrue;
p1.x=start->x;
p1.y=end->y;
p2.x=end->x;
p2.y=start->y;
mid->x=p1.x;
mid->y=p1.y;
if(MP[p1.x][p1.y]==0&&judgeLine(MP,start,&p1)&&judgeLine(MP,end,&p1))returntrue;
mid->x=p2.x;
mid->y=p2.y;
if(MP[p2.x][p2.y]==0&&judgeLine(MP,start,&p2)&&judgeLine(MP,end,&p2))returntrue;
returnfalse;
}
booljudgeTreeLines(char**MP,Point*start,Point*end,Point*mid1,Point*mid2,intn){
inti;
mid1->x=-1;mid1->y=-1;
mid2->x=-1;mid2->y=-1;
if(judgeTwoLines(MP,start,end,mid1))returntrue;
for(i=start->x-1;i>=0;i--){
if(MP[i][start->y]!=0)break;
mid1->x=i;
mid1->y=start->y;
if(judgeTwoLines(MP,mid1,end,mid2))returntrue;
}
for(i=start->x+1;i<=n+1;i++){
if(MP[i][start->y]!=0)break;
mid1->x=i;
mid1->y=start->y;
if(judgeTwoLines(MP,mid1,end,mid2))returntrue;
}
for(i=start->y-1;i>=0;i--){
if(MP[start->x][i]!=0)break;
mid1->x=start->x;
mid1->y=i;
if(judgeTwoLines(MP,mid1,end,mid2))returntrue;
}
for(i=start->y+1;i<=n+1;i++){
if(MP[start->x][i]!=0)break;
mid1->x=start->x;
mid1->y=i;
if(judgeTwoLines(MP,mid1,end,mid2))returntrue;
}
returnfalse;
}
voidptMap(char**MP,intn){
intspace=(MAXLINESIZE-n*2)/2;
inti,j;
for(i=0;i<(MAXLINESIZE-10)/2;i++)
printf("");
printf("《连连看》 ");
for(i=2;i<space;i++)printf("");
printf("x ");
for(i=1;i<=n;i++){
for(j=2;j<space;j++)
printf("");
printf("%d",i);
for(j=1;j<=n;j++)
printf("%c",pictureTable[MP[i][j]]);
printf(" ");
}
for(i=0;i<space;i++)
printf("*");
for(i=0;i<n;i++)
printf("%d*",i+1);
for(i=1;i<space;i++)
printf("*");
printf(" ");
}
char**createMap(intn){
char**ret;
inti;
ret=(char**)malloc(sizeof(char*)*(n+2));
for(i=0;i<n+2;i++)
ret[i]=(char*)malloc(sizeof(char)*(n+2));
returnret;
}
voidranMap(char**MP,intn){
int*all=(int*)malloc(sizeof(int)*n*n);
inti,tmpi,tmp;
for(i=0;i<n*n;i++)
all[i]=i/4+1;
for(i=0;i<n*n;i++){
tmpi=rand()%(n*n-i);
tmp=all[tmpi];
all[tmpi]=all[n*n-i-1];
all[n*n-i-1]=tmp;
}
for(i=0;i<n+2;i++){
MP[0][i]=0;
MP[n+1][i]=0;
MP[i][0]=0;
MP[i][n+1]=0;
}
tmpi=0;
for(i=1;i<=n;i++)
for(tmp=1;tmp<=n;tmp++)
MP[i][tmp]=all[tmpi++];
}
voiddeletePoints(char**MP,Point*p1,Point*p2){
MP[p1->x][p1->y]=0;
MP[p2->x][p2->y]=0;
}
intplayTurns(intn){
intrest=n*n;
char**mp=createMap(n),c;
ranMap(mp,n);
Pointmid1,mid2,pt1,pt2;
while(1){
ptMap(mp,n);
printf("请输入消去的坐标1(x1y1): ");
scanf("%d%d",&pt1.x,&pt1.y);
printf("请输入消去的坐标2(x2y2): ");
scanf("%d%d",&pt2.x,&pt2.y);
if((pt1.x==pt2.x&&pt1.y==pt2.y)||(pt1.x<1||pt1.x>n||pt2.x<1||pt2.x>n||pt1.y<1||pt1.y>n||pt2.y<1||pt2.y>n)){
printf("无法消除这两图案,请再次检查。");
}
elseif(mp[pt1.x][pt1.y]!=0&&mp[pt1.x][pt1.y]==mp[pt2.x][pt2.y]&&judgeTreeLines(mp,&pt1,&pt2,&mid1,&mid2,n)){
if(mid1.x==-1){
printf("Direct ");
}
elseif(mid2.x==-1){
printf("TwoLines:(%d,%d) ",mid1.x,mid1.y);
}
else{
printf("TreeLines:(%d,%d)(%d,%d) ",mid1.x,mid1.y,mid2.x,mid2.y);
}
deletePoints(mp,&pt1,&pt2);
printf("消去成功! ");
rest-=2;
if(rest==0){
printf("恭喜!你已消去所有图案! ");
break;
}
}
else{
printf("无法消除这两图案,请再次检查。");
}
printf("继续游戏(N/n不继续)?");
scanf("%c",&c);
if(c=='N'||c=='n')break;
}
printf("是否重新开局(Y/y继续)?");
scanf("%c",&c);
if(c=='y'||c=='Y')return1;
return0;
}
intmain(){
srand(time(0));
while(playTurns(4));
return0;
}
❹ 求c语言的连连看源程序
参考:
http://wapwenku..com/view/45e5361014791711cc7917f8?pn=2&vw=all&ssid=&from=&bd_page_type=1&uid=&pu=rc@1,pic@on,sl@1,pw@1000,sz@224_220,pd@1,fz@2,lp@0,tpl@color,&st=1&wk=rd&maxpage=6&pos=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+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;
}
❺ 请问有人知道怎么用c语言编程一个连连看的游戏, 能不能配图讲解一下 。跪求大神帮忙
你好!这个连连看,是DOS下程序还是窗体程序?
❻ C语言连连看
这里有VC2008的SDK连连看,我哥们这几天刚写的。。。
不过已经从最早的符合你的要求复杂到使用贴图,加了声音了。
而且支持自定义地图了。。。
实在懒得改回你要的那种程度了。。。
总体来说不是很麻烦。。。
❼ c语言课设 "连连看" 有多少不用老师就会的
老师能用就用吧,不然等毕业了,整天说:大学什么都没学到,学的东西都没用。呵呵~~
❽ 如何用c语言编写一个简单的连连看。因为要移植到ucgui上,最好是要图形化的方法。
先评我为最佳答案吧,然后给我留个信箱,我发给你,是我"多"年前学C鼓倒的。交流一下
❾ 用dev c++怎么用c语言编写一个连连看游戏写这个游戏难吗一个星期够吗
连的元素是什么? 图片?还是纯字母?
难度不高,不知你水平如何,如果是我写的话,应该几个小时就行了。