项目写最短路径,直接就是一个bfs,然后队列,有一个量指向他的上一步,代码实现就是要
#include <stdio.h>
int map[21][21] =
{
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0},
{0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0},
{0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0},
{0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0},
{0,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0},
{0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0},
{0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,0},
{0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0},
{0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0},
{0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0},
{0,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,0},
{0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0},
{0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0},
{0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0},
{0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0},
{0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
struct queue
{
int x, y;
int step;
int last;
}queue[10000];
int v[100][100];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
void bfs(int starx, int stary, int endx, int endy)
{
int tail = 1, head = 1;
v[starx][stary] = 1;
queue[tail].x = starx;
queue[tail].y = stary;
queue[tail].last = 0;
queue[tail].step = 0;
tail++;
int flag = 0;
while (head < tail)
{
for (int k = 0; k < 4; k++)
{
int xx = queue[head].x + dx[k], yy = queue[head].y + dy[k];
if (xx < 0 || xx>21 || yy < 0 || yy>21) continue;
if (map[xx][yy] == 1 && v[xx][yy] == 0)//1表示可以走
{
queue[tail].x = xx;
queue[tail].y = yy;
queue[tail].step = queue[tail - 1].step + 1;
queue[tail].last = head;
v[xx][yy] = 1;
tail++;
}
if (xx == endx && yy == endy)
{
//printf("\n%d %d %d\n",tail, xx, yy);
flag = 1;
break;
}
}
if (flag)
{
//printf("8888");
break;
}
head++;
}
int temp = queue[tail - 1].last;
//printf("%d %d %d", queue[142].last, queue[142].x, queue[142].y);
while (temp != 0)
{
printf("%d %d\n", queue[temp].x, queue[temp].y);
map[queue[temp].x][queue[temp].y] = 2;
temp = queue[temp].last;
}
}
int main()
{
bfs(1, 1, 19, 19);
for (int i = 0; i < 21; i++)
{
for (int j = 0; j < 21; j++)
{
printf("%d ", map[i][j]);
}
printf("\n");
}
}
然后就是将这个最短路得出来的路径都是2,然后我们就是根据这个2来判断是那个地方就OK
进入项目当中就是
#include <stdio.h>
#include <easyx.h>
#include <graphics.h>
#include <math.h>
#include <conio.h>
#include <time.h>
#include <cstring>
int one, zero, two, three,four,rank;
int level;
int winer, loser;
int a = 1, b = 1;//控制鼠鼠的坐标,把x y看成数组下标!然后通过数组下标来画鼠鼠
int aa, bb;
int aia=19, aib=1;//双人的对战
int aiaa, aibb;
int wg;//外挂
int wgmap[100][100];
int oneendx = 10;
int oneendy = 10;
int twoendx = 19;
int twoendy = 19;
//倒计时
char str[100];
int countdown;
clock_t Starttime;//获取开始时间 结束时间在每一个关卡里面
//关卡
int map[12][12] =//第一个地图 1为可以走,0为不能走(这样子可以不用搞最外面的边界)
{
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,0,1,1,1,0,0,0,0,0},
{0,0,1,0,0,0,1,0,1,1,1,0},
{0,1,1,1,1,0,1,1,0,0,1,0},
{0,1,0,0,1,0,0,0,1,1,1,0},
{0,1,1,1,1,0,1,1,0,0,1,0},
{0,0,0,0,1,0,1,0,1,0,1,0},
{0,1,1,0,1,0,1,0,1,0,1,0},
{0,1,1,1,1,1,1,1,1,0,1,0},
{0,0,0,0,0,0,0,0,1,1,1,0},
{0,0,1,1,1,1,1,1,1,0,1,0},
{0,0,0,0,0,0,0,0,0,0,0,0}
};
int map2[21][21] =
{
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0},
{0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0},
{0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0},
{0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0},
{0,1,1,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,0},
{0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0},
{0,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0},
{0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0},
{0,1,1,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0},
{0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,1,0},
{0,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,0,1,0},
{0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0},
{0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0},
{0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0},
{0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0},
{0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
//复制地图
int copywgmap[100][100];
int copymap[12][12];
int copymap2[21][21];
//挂
struct queue
{
int x, y;
int step;
int last;
}queue[1000];
int v[100][100];
int copyv[100][100];
struct queue copyqueue[100];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
//第一关外挂
void onebfs(int starx, int stary, int endx, int endy,int maplen)
{
int tail = 1, head = 1;
v[starx][stary] = 1;
queue[tail].x = starx;
queue[tail].y = stary;
queue[tail].last = 0;
queue[tail].step = 0;
tail++;
int flag = 0;
while (head < tail)
{
for (int k = 0; k < 4; k++)
{
int xx = queue[head].x + dx[k], yy = queue[head].y + dy[k];
if (xx < 0 || xx>maplen || yy < 0 || yy>maplen) continue;
if (map[xx][yy] == 1 && v[xx][yy] == 0)//1表示可以走
{
queue[tail].x = xx;
queue[tail].y = yy;
queue[tail].step = queue[tail - 1].step + 1;
queue[tail].last = head;
v[xx][yy] = 1;
tail++;
}
if (xx == endx && yy == endy)
{
flag = 1;
break;
}
}
if (flag)
{
break;
}
head++;
}
int temp = queue[tail - 1].last;
while (temp != 0)
{
//printf("%d %d\n", queue[temp].x, queue[temp].y);
map[queue[temp].x][queue[temp].y] = 2;//2就表示最短路
temp = queue[temp].last;
}
map[starx][stary] = 1;
}
//第二关外挂
void twobfs(int starx, int stary, int endx, int endy, int maplen)
{
int tail = 1, head = 1;
v[starx][stary] = 1;
queue[tail].x = starx;
queue[tail].y = stary;
queue[tail].last = 0;
queue[tail].step = 0;
tail++;
int flag = 0;
while (head < tail)
{
for (int k = 0; k < 4; k++)
{
int xx = queue[head].x + dx[k], yy = queue[head].y + dy[k];
if (xx < 0 || xx>maplen || yy < 0 || yy>maplen) continue;
if (map2[xx][yy] == 1 && v[xx][yy] == 0)//1表示可以走
{
queue[tail].x = xx;
queue[tail].y = yy;
queue[tail].step = queue[tail - 1].step + 1;
queue[tail].last = head;
v[xx][yy] = 1;
tail++;
}
if (xx == endx && yy == endy)
{
flag = 1;
break;
}
}
if (flag)
{
break;
}
head++;
}
int temp = queue[tail - 1].last;
while (temp != 0)
{
//printf("%d %d\n", queue[temp].x, queue[temp].y);
map2[queue[temp].x][queue[temp].y] = 2;//2就表示最短路
temp = queue[temp].last;
}
map2[starx][stary] = 1;
}
//关卡的重置
void reset()
{
one = two = three = four = rank = zero = 0;
a = b = 1;
aia = 19;
aib = 1;
wg = 0;
memcpy(map, copymap, sizeof(int) * 12 * 12);
memcpy(map2, copymap2, sizeof(int) * 21 * 21);
}
//外挂的重置
void wgreset()
{
//memcpy(map2, copymap2, sizeof(int) * 21 * 21);
//memcpy(map, copymap, sizeof(int) * 12 * 12);
for (int i = 0; i < 12; i++)
{
for (int j = 0; j < 12; j++)
{
if (map[i][j] == 2) map[i][j] = 1;
}
}
for (int i = 0; i < 21; i++)
{
for (int j = 0; j < 21; j++)
{
if (map2[i][j] == 2) map2[i][j] = 1;
}
}
memcpy(v, copyv, sizeof(int) * 100 * 100);
memcpy(queue, copyqueue, sizeof(struct queue) * 100);
}
//输掉的函数
void losedraw()
{
//切换图片加上双缓冲
BeginBatchDraw();
IMAGE img;
loadimage(&img, "./lose.jpg", 500, 500);
putimage(0, 0, &img);
FlushBatchDraw();
}
void backoragain(ExMessage* msg)
{
//重置起点和关卡
reset();
printf("鼠标位置:x:%d y:%d\n", msg->x, msg->y);
if (msg->message == WM_LBUTTONDOWN && msg->x >= 220 && msg->x <= 490 && msg->y >= 60 && msg->y <= 120)//再来一次
{
//判断是第几关 用一个level来判断
switch (level)
{
case 1:
one = 1;
loser = 0;
level = 0;
Starttime = clock();
break;
case 2:
two = 1;
loser = 0;
level = 0;
Starttime = clock();
break;
case 3:
three = 1;
loser = 0;
level = 0;
Starttime = clock();
break;
}
printf(" 第一关%d\n", one);
}
if (msg->message == WM_LBUTTONDOWN && msg->x >= 15 && msg->x <= 380 && msg->y >= 270 && msg->y <= 430)//返回主菜单
{
loser = 0;
zero = 0;
}
}
void lose()
{
losedraw();
ExMessage msg;
if (peekmessage(&msg, EM_MOUSE))
{
backoragain(&msg);
}
}
int wy, dz;
//点击鼠标获胜
void yan(ExMessage* msg)
{
printf("%d\n", zero);
if (msg->message == WM_LBUTTONDOWN && msg->x >= 0 && msg->x <= 500 && msg->y >= 0 && msg->y <= 500)
{
dz = wy = 0;
zero = 0;
printf("%d\n", zero);
}
}
//王源获胜
void wangyuan()
{
BeginBatchDraw();
IMAGE img;
loadimage(&img, "./renwin.jpg", 500, 500);
putimage(0, 0, &img);
ExMessage msg;
if (peekmessage(&msg, EM_MOUSE))
{
yan(&msg);
}
FlushBatchDraw();
}
void dingzhen()
{
BeginBatchDraw();
IMAGE img;
loadimage(&img, "./aiwin.jpg", 500, 500);
putimage(0, 0, &img);
ExMessage msg;
if (peekmessage(&msg, EM_MOUSE))
{
yan(&msg);
}
FlushBatchDraw();
}
//关卡
//到达终点 倒计时结束判断
void shuexport()
{
if (one == 1)
{
if (a == 10 && b == 10)
{
int is_ok = MessageBox(GetHWnd(), "帮助牛爷爷打败沸羊羊", "阿里嘎多美羊羊桑", MB_OKCANCEL);
if (is_ok==IDOK)
{
one = 0;
two = 1;
a = 1;
b = 1;
Starttime = clock();
}
else
{
one = 0;
zero = 0;
}
}
//倒计时结束的处理
if (countdown < 0)
{
zero = 1;
three = two = one = 0;
loser = 1;
//printf("\n%d %d %d %d\n", zero, one, loser, countdown);
}
}
if (two == 1)
{
if (a == 19 && b == 19)
{
int is_ok = MessageBox(GetHWnd(), "王源丁真", "阿里嘎多美羊羊桑", MB_OKCANCEL);
if (is_ok == IDOK)
{
two = 0;
three = 1;
a = 1;
b = 1;
//Starttime = clock();
}
else
{
one = 0;
zero = 0;
}
}
//倒计时结束的处理
if (countdown < 0)
{
zero = 1;
three = two = one = 0;
loser = 1;
//printf("\n%d %d %d %d\n", zero, one, loser, countdown);
}
}
if (three == 1)
{
//printf("%d %d\n", a, b);
if (a == 11 && b == 19)
{
three = 0;
wy = 1;
//wangyuan();//王源获胜
}
if (aia == 11 && aib == 19)
{
three = 0;
dz = 1;
//dingzhen();//丁真获胜
}
}
}
//画图
void draw(int maplen,int imagelen)
{
//画图要在这个双缓冲里面
BeginBatchDraw();
//加载背景图片
if (one == 1)
{
IMAGE img;
loadimage(&img, "./niu.jpg", 500, 500);
putimage(0, 0, &img);
}
if (two == 1)
{
IMAGE img;
loadimage(&img, "./twobk.jpg", 500, 500);
putimage(0, 0, &img);
}
if (three == 1)
{
IMAGE img;
loadimage(&img, "./threebk.jpg", 500, 500);
putimage(0, 0, &img);
}
//绘制返回按钮
settextstyle(30, 0, "华文彩云");
outtextxy(20, 15, "返回");
//下面是地图的绘画
//定义墙壁的图片 墙壁的绘制
IMAGE wall;
loadimage(&wall, "./wall.jpg", imagelen, imagelen);
if (one == 1)//第一关地图
{
//终点绘制
IMAGE end;
loadimage(&end, "./end.jpg", imagelen, imagelen);
putimage(50 + (imagelen * oneendx), 50 + (imagelen * oneendy), &end);
//鼠鼠的绘制
IMAGE role;
loadimage(&role, "./dog.jpg", imagelen, imagelen);
setfillcolor(BLACK);
if (a >= 0 && a < maplen && b >= 0 && b < maplen && map[a][b])//如果这个点在地图上为ok那么我们就画
{
int drawmousex = b;
int drawmousey = a;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role);
aa = a;
bb = b;
}
else
{
int drawmousex = bb;
int drawmousey = aa;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role);
a = aa;
b = bb;
}
for (int i = 0; i < maplen; i++)
{
for (int j = 0; j < maplen; j++)
{
if (!map[i][j])//j表示x i表示yf
{
int drawx = j;
int drawy = i;
putimage(50 + (drawx * imagelen), 50 + (drawy * imagelen), &wall);
//fillrectangle(50+(30*j), 50 + (30 * i), 50 + (30 * j)+30, 50 + (30 * i)+30);
}
//printf("%d %d %d\n ",i,j,map[i][j]);
//illrectangle(i , j , i + 20, j + 20);
}
}
}
if (two == 1)
{
//printf("%d %d", a, b);
//终点绘制
IMAGE end;
loadimage(&end, "./two.jpg", imagelen, imagelen);
putimage(50 + (imagelen * twoendx), 50 + (imagelen * twoendy), &end);
//鼠鼠的绘制
IMAGE role;
loadimage(&role, "./tworole.jpg", imagelen, imagelen);
if (a >= 0 && a < maplen && b >= 0 && b < maplen && map2[a][b])//如果这个点在地图上为ok那么我们就画
{
int drawmousex = b;
int drawmousey = a;
printf("%d %d\n", a, b);
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role);//把它看作鼠鼠
aa = a;
bb = b;
}
else
{
int drawmousex = bb;
int drawmousey = aa;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role);
a = aa;
b = bb;
}
for (int i = 0; i < maplen; i++)
{
for (int j = 0; j < maplen; j++)
{
if (!map2[i][j])//j表示x i表示y
{
int drawx = j;
int drawy = i;
putimage(50 + (drawx * imagelen), 50 + (drawy * imagelen), &wall);
}
}
}
}
if (three == 1)//双人对战
{
IMAGE end;
loadimage(&end, "./threeend.jpg", imagelen, imagelen);
putimage(50 + (imagelen * 19), 50 + (imagelen * 11), &end);
//printf("%d %d\n", aia, aib);
IMAGE role1;
loadimage(&role1, "./dingzhen.jpg", imagelen, imagelen);
IMAGE role2;
loadimage(&role2, "./wangyuan.jpg", imagelen, imagelen);
if (a >= 0 && a < maplen && b >= 0 && b < maplen && map2[a][b])//如果这个点在地图上为ok那么我们就画
{
int drawmousex = b;
int drawmousey = a;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role2);//把它看作鼠鼠
aa = a;
bb = b;
}
else
{
int drawmousex = bb;
int drawmousey = aa;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role2);
a = aa;
b = bb;
}
if (aia >= 0 && aia < maplen && aib >= 0 && aib < maplen && map2[aia][aib])//如果这个点在地图上为ok那么我们就画
{
int drawmousex = aib;
int drawmousey = aia;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role1);//把它看作鼠鼠
aiaa = aia;
aibb = aib;
}
else
{
int drawmousex = aibb;
int drawmousey = aiaa;
putimage(50 + (imagelen * drawmousex), 50 + (imagelen * drawmousey), &role1);
aia = aiaa;
aib = aibb;
}
for (int i = 0; i < maplen; i++)
{
for (int j = 0; j < maplen; j++)
{
if (!map2[i][j])//j表示x i表示y
{
int drawx = j;
int drawy = i;
putimage(50 + (drawx * imagelen), 50 + (drawy * imagelen), &wall);
}
}
}
}
//最短路的绘制
if ((one == 1 || two == 1)&&wg==1)
{
for (int i = 0; i < maplen; i++)
{
for (int j = 0; j < maplen; j++)
{
if (map[i][j]==2&&one==1)//j表示x i表示yf
{
int drawx = j;
int drawy = i;
setfillcolor(RED);
//putimage(50 + (drawx * imagelen), 50 + (drawy * imagelen), &wall);
fillrectangle(50+(30*j), 50 + (30 * i), 50 + (30 * j)+30, 50 + (30 * i)+30);
}
if (map2[i][j] == 2 && two == 1)
{
int drawx = j;
int drawy = i;
setfillcolor(RED);
//putimage(50 + (drawx * imagelen), 50 + (drawy * imagelen), &wall);
fillrectangle(50 + (17 * j), 50 + (17 * i), 50 + (17 * j) + 17, 50 + (17 * i) + 17);
}
//printf("%d %d %d\n ",i,j,map[i][j]);
//illrectangle(i , j , i + 20, j + 20);
}
}
}
//倒计时的绘制
if (!three)
{
setbkmode(TRANSPARENT);
settextstyle(30, 0, "华文行楷");
settextcolor(BLACK);
//printf("%s", str);
outtextxy(420, 420, str);
}
FlushBatchDraw();
}
//鼠鼠的移动
void yidong()//通过全局变量x y来确定鼠鼠的移动
{
//改变的是二维数组的地方 然后我们画图再重新定义两个变量map[a][b]
if (_kbhit() != 0)//判断是否有键盘输入,防止_getch()导致函数卡着不动
{
char key = _getch();
switch (key)
{
case 72:
a -= 1;
//yy += 1;
//printf("上键\n");
break;
case 80:
a += 1;
//yy -= 1;
//printf("下键\n");
break;
case 75:
b -= 1;
//xx += 1;
//printf("左键\n");
break;
case 77:
b += 1;
//xx -= 1;
//printf("右键\n");
break;
case 'w':
aia -= 1;
break;
case 's':
aia += 1;
break;
case 'a':
aib -= 1;
break;
case 'd':
aib += 1;
break;
case ' ':
if (one == 1)
{
wgreset();
//printf("%d %d\n", a, b);
if (wg == 1)
{
wg = 0;
wgreset();
}
else
{
onebfs(a, b, oneendy, oneendx, 12);
wg = 1;
}
break;
}
if (two == 1)
{
//wgreset();
if (wg == 1)
{
wg = 0;
wgreset();
}
else
{
twobfs(a, b, twoendy, twoendx, 21);
wg = 1;
}
break;
}
}
}
}
//返回主菜单按钮
void back(ExMessage* msg)
{
//printf("鼠标位置:x:%d y:%d\n", msg->x, msg->y);
if (msg->message == WM_LBUTTONDOWN && msg->x >= 20 && msg->x <= 80 && msg->y >= 15 && msg->y <= 45)
{
//重置关卡
reset();
}
}
//路变墙 墙变路
void change(ExMessage* msg,int imagelen)
{
if (msg->message == WM_LBUTTONDOWN && msg->x >= 50 && msg->x <= 410 && msg->y >= 50 && msg->y <= 410)
{
//printf("鼠标位置:x:%d y:%d\n", msg->x, msg->y);
int indexx = (msg->x - 50) / imagelen;//表示b
int indexy = (msg->y - 50) / imagelen;//表示a
printf(" %d %d\n", indexy, indexx);
if (one == 1)
{
if (map[indexy][indexx])
{
map[indexy][indexx] = 0;
//printf("ok");
}
else
{
map[indexy][indexx] = 1;
}
printf(" 地图:%d ", map[indexy][indexx]);
}
if (two == 1)
{
if (map2[indexy][indexx])
{
map2[indexy][indexx] = 0;
//printf("ok");
}
else
{
map2[indexy][indexx] = 1;
}
printf(" 地图:%d ", map2[indexy][indexx]);
}
}
}
//倒计时
void time()
{
int Endtime = clock();
countdown = (int)((Endtime - Starttime) / CLOCKS_PER_SEC);
if (one == 1)
{
countdown = 100 - countdown;//控制几秒倒计时
}
if (two == 1)
{
countdown = 90 - countdown;//控制几秒倒计时
}
sprintf_s(str, "%d s", countdown);
//printf("%d ", countdown);
}
//关卡的主函数
void apex(int ztlevel,int maplen,int imagelen)
{
level = ztlevel;
//画图
draw(maplen,imagelen);
//倒计时
time();
//控制返回主界面 墙变路 路变墙
ExMessage msg;
if (peekmessage(&msg, EM_MOUSE))
{
//printf("88888");
//返回主菜单
back(&msg);
//路变墙 墙变路
change(&msg,imagelen);
}
//控制鼠鼠移动
yidong();
//判断鼠鼠有没有到出口的函数 以及时间到达的处理
shuexport();
}
//排行榜
void Rankdraw()
{
BeginBatchDraw();//双缓冲
IMAGE img;
loadimage(&img, "./win.jpg", 500, 500);
putimage(0, 0, &img);
//绘制返回按键
setbkmode(TRANSPARENT);
settextstyle(30, 0, "华文彩云");
outtextxy(20, 15, "返回");
outtextxy(150, 150, "第一关排行榜");
outtextxy(150, 200, "第二关排行榜");
outtextxy(150, 250, "第三关排行榜");
FlushBatchDraw();
}
void rankmousedown(ExMessage* msg)
{
if (msg->message == WM_LBUTTONDOWN && msg->x >= 20 && msg->x <= 80 && msg->y >= 15 && msg->y <= 45)
{
//重置关卡
reset();
}
}
void Rank()
{
Rankdraw();
ExMessage msg;
if (peekmessage(&msg, EM_MOUSE))
{
rankmousedown(&msg);
}
}
//主菜单
//主菜单通往各个界面
void mousedown(ExMessage* msg)
{
//printf("鼠标位置:x:%d y:%d\n", msg->x, msg->y);
if (msg->message == WM_LBUTTONDOWN && msg->x >= 200 && msg->x <= 290 && msg->y >= 150 && msg->y <= 180)//第一关
{
one = 1;
zero = 1;
Starttime = clock();
}
if (msg->message == WM_LBUTTONDOWN && msg->x >= 200 && msg->x <= 290 && msg->y >= 200 && msg->y <= 230)//第二关
{
two = 1;
zero = 1;
Starttime = clock();
}
if (msg->message == WM_LBUTTONDOWN && msg->x >= 200 && msg->x <= 290 && msg->y >= 250 && msg->y <= 280)//第三关双人对战
{
three = 1;
zero = 1;
Starttime = clock();
}
if (msg->message == WM_LBUTTONDOWN && msg->x >= 200 && msg->x <= 290 && msg->y >= 300 && msg->y <=330 )//第四关
{
four = 1;
zero = 1;
Starttime = clock();
}
if (msg->message == WM_LBUTTONDOWN && msg->x >= 200 && msg->x <= 290 && msg->y >= 350 && msg->y <= 380)//排行榜
{
rank = 1;
zero = 1;
}
}//主菜单的
void home()
{
//背景图
//reset();
IMAGE img;
loadimage(&img, "./shu.jpg", 500, 500);
putimage(0, 0, &img);
//第一关图片
BeginBatchDraw();//双缓冲
setbkmode(TRANSPARENT);
settextstyle(30, 0, "华文彩云");
outtextxy(200, 150, "第一关");
outtextxy(200, 200, "第二关");
outtextxy(200, 250, "第三关");
outtextxy(200, 300, "chase");
outtextxy(200, 350, "排行榜");
//fillrectangle(200, 150, 290, 180);
ExMessage msg;
if (peekmessage(&msg, EM_MOUSE))
{
mousedown(&msg);
}
FlushBatchDraw();
}//主菜单
int main()
{
memcpy(copymap, map, sizeof(int) * 12 * 12);
memcpy(copymap2, map2, sizeof(int) * 21 * 21);
memcpy(copyv, v, sizeof(int) * 100 * 100);
memcpy(copywgmap, wgmap, sizeof(int) * 100 * 100);
memcpy(copyqueue, queue, sizeof(struct queue) * 100);
initgraph(500, 500, SHOWCONSOLE);
while (true)
{
if (zero == 0)
{
home();
}
if (one == 1)
{
apex(1,12,30);//简单的关卡
}
if (two == 1)
{
apex(2, 21, 17);
}
if (three == 1)
{
apex(3, 21, 17);
}
if (rank == 1)
{
Rank();
}
if (loser == 1)
{
lose();
}
if (wy == 1)
{
wangyuan();
}
if (dz == 1)
{
dingzhen();
}
}
getchar();
}
然后现在就是差文件的操作了,把排行榜搞出来就ok
下班下班,明天直接写完!