當前位置:首頁 » 編程語言 » 連連看難度選擇c語言實現
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

連連看難度選擇c語言實現

發布時間: 2022-07-07 22:58:26

❶ 如何用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語言編寫一個連連看游戲寫這個游戲難嗎一個星期夠嗎

連的元素是什麼? 圖片?還是純字母?
難度不高,不知你水平如何,如果是我寫的話,應該幾個小時就行了。