老鼠走迷宫

 

 

 

 

 

 

 

 

#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<easyx.h>
#include<conio.h>
#include<graphics.h>
#include<time.h>
clock_t Start_time;
clock_t End_time;
IMAGE ms,wh,wa,fir,des,pas,com,way;
char num = { '1' };
char shortway[] = { "最短路径" };
char allway[] = { "全部路径" };
char one[] = { "第 1 关" };
char two[] = { "第 2 关" };
char three[] = { "第 3 关" };
char four[] = { "第 4 关" };
char five[] = { "第 5 关" };
int w, h;
int op;
int parent[450];//树结构
int last;//终点在que中的位置
enum mine
{
	space,//0
	wall,//1
	mouse,//2
	dest,//3
};
int level;//当前地图
int all = 0;//地图数量
//初始地图
int mapp[5][22][22] = 
{
	{
		{1,1,1,1,1,1,1,1,1,1,1,1},
		{1,2,0,0,0,0,0,0,0,0,0,1},
		{1,0,1,1,1,1,1,1,1,1,0,1},
		{1,0,0,0,0,0,0,0,0,1,0,1},
		{1,1,1,1,1,0,1,1,0,1,0,1},
		{1,0,1,0,1,0,0,1,1,1,1,1},
		{1,1,0,1,0,1,0,0,0,0,3,1},
		{1,1,1,1,1,1,1,1,1,1,1,1},
	},
	{
		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
		{1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
		{1,0,1,1,0,1,1,1,0,1,0,1,1,0,1,1},
		{1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1},
		{1,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1},
		{1,0,0,0,1,0,0,1,0,1,0,1,0,1,0,1},
		{1,0,1,0,1,0,1,0,1,0,1,1,0,0,1,1},
		{1,0,0,0,1,1,1,0,0,0,1,1,1,0,3,1},
		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	},
	{
		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
		{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1},
		{1,0,0,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1},
		{1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1},
		{1,0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1},
		{1,0,0,1,0,0,0,0,1,1,2,1,0,0,0,0,1,0,1,0,1},
		{1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,1},
		{1,0,1,1,1,1,1,0,1,0,0,1,0,0,0,0,0,1,1,1,1},
		{1,0,1,0,0,0,1,0,1,1,0,1,1,1,1,1,0,0,0,0,1},
		{1,0,1,0,1,0,1,1,1,0,0,0,1,0,0,1,0,1,1,1,1},
		{1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
		{1,0,1,0,1,0,0,0,1,0,0,1,1,1,0,1,1,1,1,1,1},
		{1,0,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,1,0,0,1},
		{1,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,0,0,1},
		{1,0,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,1},
		{1,0,0,1,0,0,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1},
		{1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,1},
		{1,0,0,1,0,0,0,1,0,1,0,0,0,1,1,1,1,0,1,0,1},
		{1,0,0,1,0,0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,1},
		{1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,3,1},
		{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	}
};
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
struct point {
	int x;
	int y;
	int step;
}que[500];//队列
point stk[500];//栈
int top;
struct tt {
	char s[20];
	int ti;
}t[5];
void find_s(int* x, int* y,int m)//找到起点
{
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
		{
			if (mapp[m][i][j] == mouse)
			{
				*x = i;
				*y = j;
				return;
			}
		}
	}
}
void find_f(int* x, int* y, int m)//找到终点
{
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
		{
			if (mapp[m][i][j] == dest)
			{
				*x = i;
				*y = j;
				return;
			}
		}
	}
}
bool bfs(int sx, int sy, int fx, int fy,int m)//检查地图是否合理
{
	int book[22][22] = { 0 };
	que[1] = { sx,sy,0 };
	parent[1] = 1;
	book[sx][sy] = 1;
	int tx, ty;
	int head = 1;
	int tail = 1;
	while (head <=tail)
	{
		int nx = que[head].x, ny = que[head].y;
		if (book[fx][fy] == 1)
		{
			return true;
		}
		for (int i = 0; i < 4; i++)
		{
			tx = nx + dx[i];
			ty = ny + dy[i];
			if (tx >= 0 && tx < 22 && ty >= 0 && ty < 22)//防止越界
			{
				if (book[tx][ty] == 0 && (mapp[m][tx][ty] == space|| mapp[m][tx][ty] == dest))
				{
					que[++tail] = { tx,ty,que[head].step+1};//入队
					if (tx == fx && ty == fy)
					{
						last = tail;
					}
					parent[tail] = head;//tail的父亲是head
					book[tx][ty] = 1;
				}
			}
		}
		head++;//出队
	}
	if (book[fx][fy] == 1) return true;
	else return false;
}
void gamedraw()//开始游戏后的地图绘制
{
	BeginBatchDraw();//双缓冲
	cleardevice();
	settextstyle(45, 0, "楷体");//文字样式 高度 宽度 字体
	outtextxy(30 * 22 + 30, 30, "第  关");
	outtextxy(30 * 23 + 70, 30, num);//第几关
	rectangle(30 * 22 + 30, 90, 30 * 30 - 40, 150);
	End_time = clock();
	t[level].ti = (int)((End_time - Start_time) / CLOCKS_PER_SEC);//CLOCKS_PER_SEC 系统单位时间/秒
	char str[10];
	sprintf_s(str, "%d/60s",t[level].ti);
	outtextxy(700 + w, 85 + h, str);
	rectangle(30 * 22 + 30, 210, 30 * 30 - 40, 270);//690,
	outtextxy(30 * 22 + 30 + w, 205 + h,shortway);//最短路径
	rectangle(30 * 22 + 30, 330, 30 * 30 - 40, 390);
	outtextxy(690 + w, 325 + h, allway);//全部路径
	//rectangle(30 * 22 + 30, 450, 30 * 30 - 40, 510);
	settextstyle(20, 0, "楷体");//文字样式 高度 宽度 字体
	outtextxy(680, 400, "wasd/上下左右 移动老鼠");
	outtextxy(680, 430, "最短路径 1");
	outtextxy(680, 460, "全部路径 2");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
		{
			switch (mapp[level][i][j])
			{
			case space:
				printf(" ");
				putimage(j * 30, i * 30, &wh);
				break;
			case wall:
				printf("#");
				putimage(j * 30, i * 30, &wa);
				break;
			case mouse:
				printf("@");
				putimage(j * 30, i * 30, &ms);
				break;
			case dest:
				printf("!");
				putimage(j * 30, i * 30, &des);
				break;
			case mouse+dest:
				printf("$");
				break;
			}
		}
		printf("\n");
	}
	rectangle(0,0,30*22, 30*22);
	EndBatchDraw();//双缓冲
}
bool judge()//判断是否通关
{
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
		{
			if (mapp[level][i][j] == mouse + dest)
			{
				return true;
			}
		}
	}
	return false;
}
void fastway(int x)//输出最短路径
{
	while (x != parent[x])
	{
		int i = que[x].y;
		int j = que[x].x;
		putimage(i * 30, j * 30, &way);
		x = parent[x];
	}
}
void dfs(int sx, int sy, int fx, int fy, int m,int book[22][22])
{
	if (sx == fx && sy == fy)
	{
		for (int i = 0; i < top; i++)
		{
			putimage(stk[i].y*30, stk[i].x*30, &way);
		}
		return;
	}
	int tx, ty;
	for (int i = 0; i < 4; i++)
	{
		tx = sx + dx[i];
		ty = sy + dy[i];
		if (tx >= 0 && tx < 22 && ty >= 0 && ty < 22)//防止越界
		{
			if (book[tx][ty] == 0 && (mapp[m][tx][ty] == space || mapp[m][tx][ty] == dest))
			{
				book[tx][ty] = 1;
				stk[top++] = { tx,ty };
				dfs(tx, ty, fx, fy, m, book);
				top--;
				book[tx][ty] = 0;
			}
		}
	}
	
}
void keyevent()//运动老鼠,键盘消息
{
	int nx = 0, ny = 0; int fx, fy;
	int flag = 0;
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
		{
			if (mapp[level][i][j] == mouse)
			{
				nx = i;
				ny = j;
				flag = 1;
				break;
			}
		}
		if (flag) break;
	}
	char key = _getch();//阻塞函数
	switch (key)
	{
	case 72:
	case 'w':
	case'W'://上
		if ((mapp[level][nx - 1][ny] == space || mapp[level][nx - 1][ny] == dest )&& nx - 1 >= 0)
		{
			mapp[level][nx - 1][ny] += mouse;
			mapp[level][nx][ny] -= mouse;
		}
		break;
	case 80:
	case 's':
	case 'S'://下
		if ((mapp[level][nx + 1][ny] == space || mapp[level][nx + 1][ny] == dest )&& nx + 1 <22 )
		{
			mapp[level][nx + 1][ny] += mouse;
			mapp[level][nx][ny] -= mouse;
		}
		break;
	case 75:
	case 'a':
	case'A'://左
		if ((mapp[level][nx][ny-1] == space || mapp[level][nx][ny - 1] == dest )&& ny - 1 >=0)
		{
			mapp[level][nx][ny-1] += mouse;
			mapp[level][nx][ny] -= mouse;
		}
		break;
	case 77:
	case 'd':
	case 'D'://右
		if ((mapp[level][nx][ny+1] == space || mapp[level][nx][ny + 1] == dest )&& ny + 1 < 22)
		{
			mapp[level][nx][ny+1] += mouse;
			mapp[level][nx][ny] -= mouse;
		}
		break;
	case '1':
		find_f(&fx, &fy, level);
		bfs(nx, ny, fx, fy, level);//最短路
		fastway(last);
		Sleep(1000);
		break;
	case '2':
		int book[22][22] = { 0 };
		find_f(&fx, &fy, level);
		dfs(nx,ny,fx,fy,level,book);
		Sleep(1000);
		break;
	}
}
void savetime()//保存时间
{
	FILE* fp = fopen("./time.txt", "wb");
	for (int i = 0; i < 5; i++)
	{
		fwrite(&t[i], sizeof(tt), 1, fp);
	}
	fclose(fp);
}
void readtime()//读取闯关记录
{
	FILE* fp = fopen("./time.txt", "rb");
	for (int i = 0; i < 5; i++)
	{
		fread(&t[i], sizeof(tt), 1, fp);
	}
	fclose(fp);
}
void start()//开始游戏
{
	Start_time = clock();
	while (1)
	{
		system("cls");//清屏
		gamedraw();
		if (t[level].ti > 60)
		{
			int	ret=MessageBox(GetHWnd(), "很遗憾,闯关失败", "提示", MB_OKCANCEL);
			if (ret == IDOK)
			{
				break;
			}
		}
		if (judge())
		{
			printf("succeess");
			level++;
			num++;
			Start_time = clock();
			if (level >= all)
			{
				printf("\ngame clearance");
				putimage(0, 0, &pas);
				savetime();
				int	ret = MessageBox(GetHWnd(), "闯关成功,时间已记录", "提示", MB_OKCANCEL);
				break;
			}
		}
		keyevent();
	}
}
void changedraw()
{
	BeginBatchDraw();//双缓冲
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
		{
			switch (mapp[op][i][j])
			{
			case space:
				printf(" ");
				putimage(j * 30, i * 30, &wh);
				break;
			case wall:
				printf("#");
				putimage(j * 30, i * 30, &wa);
				break;
			case mouse:
				printf("@");
				putimage(j * 30, i * 30, &ms);
				break;
			case dest:
				printf("!");
				putimage(j * 30, i * 30, &des);
				break;
			case mouse + dest:
				printf("$");
				break;
			}
		}
		printf("\n");
	}
	rectangle(0, 0, 30 * 22, 30 * 22);
	EndBatchDraw();
}
void savemap()//保存地图到文件
{
	FILE *fp = fopen("./text1.txt", "w");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fprintf(fp, "%d\t", mapp[0][i][j]);
		fprintf(fp, "%c", '\n');
	}
	fclose(fp);
	fp = fopen("./text2.txt", "w");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fprintf(fp, "%d\t", mapp[1][i][j]);
		fprintf(fp, "%c", '\n');
	}
	fclose(fp);
	fp = fopen("./text3.txt", "w");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fprintf(fp, "%d\t", mapp[2][i][j]);
		fprintf(fp, "%c", '\n');
	}
	fclose(fp);
	fp = fopen("./text4.txt", "w");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fprintf(fp, "%d\t", mapp[3][i][j]);
		fprintf(fp, "%c", '\n');
	}
	fclose(fp);
	fp = fopen("./text5.txt", "w");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fprintf(fp, "%d\t", mapp[4][i][j]);
		fprintf(fp, "%c", '\n');
	}
	fclose(fp);
}
void readmap()//从文件中读取地图
{
	FILE* fp;
	fp = fopen("./text1.txt", "r");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fscanf(fp, "%d\t", &mapp[0][i][j]);
		fscanf(fp, "\n");
	}
	fclose(fp);
	fp = fopen("./text2.txt", "r");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fscanf(fp, "%d\t", &mapp[1][i][j]);
		fscanf(fp, "\n");
	}
	fclose(fp);
	fp = fopen("./text3.txt", "r");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fscanf(fp, "%d\t", &mapp[2][i][j]);
		fscanf(fp, "\n");
	}
	fclose(fp);
	fp = fopen("./text4.txt", "r");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fscanf(fp, "%d\t", &mapp[3][i][j]);
		fscanf(fp, "\n");
	}
	fclose(fp);
	fp = fopen("./text5.txt", "r");
	for (int i = 0; i < 22; i++)
	{
		for (int j = 0; j < 22; j++)
			fscanf(fp, "%d\t", &mapp[4][i][j]);
		fscanf(fp, "\n");
	}
	fclose(fp);
}
void change()
{
	changedraw();
	rectangle(30 * 22 + 30, 90, 30 * 30 - 40, 150);
	outtextxy(690 + w, 85 + h, one);
	rectangle(30 * 22 + 30, 210, 30 * 30 - 40, 270);
	outtextxy(690 + w, 205 + h, two);
	rectangle(30 * 22 + 30, 330, 30 * 30 - 40, 390);
	outtextxy(690 + w, 325 + h, three);
	if (all == 4)
	{
		rectangle(30 * 22 + 30, 450, 30 * 30 - 40, 510);
		outtextxy(690 + w, 445 + h, four);
		rectangle(30 * 22 + 30, 570, 30 * 30 - 40, 630);
		outtextxy(690 + w, 565 + h, "  新建  ");
	}
	else if(all==3)
	{
		rectangle(30 * 22 + 30, 450, 30 * 30 - 40, 510);
		outtextxy(690 + w, 445 + h, "  新建  ");
	}
	else if (all == 5)
	{
		rectangle(30 * 22 + 30, 570, 30 * 30 - 40, 630);
		outtextxy(690 + w, 565 + h, five);
		rectangle(30 * 22 + 30, 450, 30 * 30 - 40, 510);
		outtextxy(690 + w, 445 + h, four);
	}
	while (1)//选择需要编辑的地图,最多支持5张
	{
		if (MouseHit())
		{
			MOUSEMSG msg = GetMouseMsg();
			if (msg.uMsg == WM_LBUTTONDOWN)
			{
				if (msg.x >= 690 && msg.x <= 860 && msg.y >= 90 && msg.y <= 150)
				{
					op = 0;
					break;
				}
				if (msg.x >= 690 && msg.x <= 860 && msg.y >= 210 && msg.y <= 270)
				{
					op = 1;
					break;
				}
				if (msg.x >= 690 && msg.x <= 860 && msg.y >= 330 && msg.y <= 390)
				{
					op = 2;
					break;
				}
				if (msg.x >= 690 && msg.x <= 860 && msg.y >= 450 && msg.y <= 510)
				{
					op = 3;
					break;
				}
				if (msg.x >= 690 && msg.x <= 860 && msg.y >= 570 && msg.y <= 630)
				{
					op = 4;
					break;
				}
			}
		}
	}
	cleardevice();
	rectangle(30 * 22 + 30, 90, 30 * 30 - 40, 150);
	outtextxy(690 + w, 85 + h, "设置起点");
	rectangle(30 * 22 + 30, 210, 30 * 30 - 40, 270);
	outtextxy(690 + w, 205 + h, "设置终点");
	rectangle(30 * 22 + 30, 330, 30 * 30 - 40, 390);
	outtextxy(690 + w, 325 + h, "检测地图");
	rectangle(30 * 22 + 30, 450, 30 * 30 - 40, 510);
	outtextxy(690 + w, 445 + h, "  保存  ");
	rectangle(30 * 22 + 30, 570, 30 * 30 - 40, 630);
	outtextxy(690 + w, 565 + h, "  重置  ");
	int sx=-1, sy=-1;
	int fx = -1, fy = -1;
	while (1)
	{
		changedraw();
		int x, y;
		while (1)
		{
			if (MouseHit())
			{
				MOUSEMSG msg = GetMouseMsg();
				if (msg.uMsg == WM_LBUTTONDOWN)
				{
					if (msg.x <= 30 * 22 && msg.y <= 30 * 22)//编辑墙和空地
					{
						x = msg.y / 30;
						y = msg.x / 30;
				  		if (mapp[op][x][y] == 0) mapp[op][x][y] = 1;
						else if (mapp[op][x][y] == 1) mapp[op][x][y] = 0;
						break;
					}
					if (msg.x >= 30 * 22 + 30 && msg.x <= 30 * 30 - 40 && msg.y >= 450 && msg.y <= 510)//点击保存
					{
						find_s(&sx,&sy,op);
						find_f(&fx, &fy, op);
						if (sx != -1 && sy != -1&&fx!=-1&&fy!=-1)
						{
							if (bfs(sx, sy, fx, fy,op)==true)
							{
								int ret = MessageBox(GetHWnd(),  "能够到达终点,是否保存","提示", MB_OKCANCEL);
								if (ret == IDOK)
								{
									savemap();
									return;
								}
							}
							else
							{
								MessageBox(GetHWnd(),  "无法到达终点","提示", MB_OKCANCEL);
							}
						}
						
					}
					if (msg.x >= 30 * 22 + 30 && msg.x <= 30 * 30 - 40 && msg.y >= 90 && msg.y <= 150)//点击设置起点
					{
						find_s(&sx, &sy, op); 
						int ret = MessageBox(GetHWnd(), "是否设置起点", "提示", MB_OKCANCEL);
						if (ret == IDCANCEL)
						{
							continue;
						}
						while (1)
						{
							if (MouseHit())
							{
								MOUSEMSG msg1 = GetMouseMsg();
								if (msg1.uMsg == WM_LBUTTONDOWN)
								{
									if (msg1.x <= 30 * 22 && msg1.y <= 30 * 22)
									{
										x = msg1.y / 30;
										y = msg1.x / 30;
										if (sx != -1 && sy != -1)mapp[op][sx][sy] = space;
										mapp[op][x][y] = mouse;
										break;
									}
								}
							}
						}
					}
					if (msg.x >= 30 * 22 + 30 && msg.x <= 30 * 30 - 40 && msg.y >= 210 && msg.y <= 270)//点击设置终点
					{
						find_f(&fx, &fy, op);
						int ret = MessageBox(GetHWnd(), "是否设置终点", "提示", MB_OKCANCEL);
						if (ret == IDCANCEL)
						{
							continue;
						}
						while (1)
						{
							if (MouseHit())
							{
								MOUSEMSG msg2 = GetMouseMsg();
								if (msg2.uMsg == WM_LBUTTONDOWN)
								{
									if (msg2.x <= 30 * 22 && msg2.y <= 30 * 22)
									{
										x = msg2.y / 30;
										y = msg2.x / 30;
										if (fx != -1 && fy != -1)mapp[op][fx][fy] = space;
										mapp[op][x][y] = dest;
										break;
									}
								}
							}
						}
					}
				}
			}
		}

	}
}
void num_ofmap()//判断地图数量
{
	int flag = 0;
	for (int i = 0; i < 5; i++)
	{
		flag = 0;
		for (int j = 0; j < 22; j++)
		{
			for (int k = 0; k < 22; k++)
			{
				if (mapp[i][j][k] != 0)
				{
					all++;
					flag = 1;
					break;
				}
			}
			if (flag) break;
		}
	}
}
void sort(int n)//对时间排序
{
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (t[i].ti > t[j].ti)
			{
				tt temp = t[i];
				t[i] = t[j];
				t[j] = temp;
			}
		}
	}
}
int main()
{
	initgraph(30*30, 30*22);
	setbkcolor(WHITE);//设置背景
	cleardevice();
	loadimage(&ms,"./mouse.jpg", 30,30);
	loadimage(&wh, "./white.jpg", 30, 30);
	loadimage(&wa, "./wall.jpg", 30, 30);
	loadimage(&fir, "./first.jpeg", 30 * 30, 30 * 22);
	loadimage(&des, "./dest.png", 30, 30);
	loadimage(&pas, "./pass.png", 30 * 30, 30 * 22);
	loadimage(&com, "./complete.png", 30 * 30, 30 * 22);
	loadimage(&way, "./way.png", 30, 30);
	putimage(0, 0, &fir);
	setlinestyle(PS_SOLID, 5);//设置线条样式
	setlinecolor(RED);
	rectangle(30 * 10, 30 * 20 / 5, 30 * 20, 30 * 20 / 5 * 2);//300,120,600,240
	rectangle(30 * 10, 30 * 20 / 5 * 3, 30 * 20, 30 * 20 / 5 * 4);//300,360,600,480
	rectangle(350+300, 550, 550+300, 620);
	setbkmode(TRANSPARENT);//透明
	settextcolor(RED);//文字颜色
	settextstyle(80, 0, "楷体");//文字样式 高度 宽度 字体
	char play[] = { "开始游戏" };
	w = 300/2 - textwidth(play) / 2;
	h = 120/2 - textheight(play) / 2;
	outtextxy(300 + w, 120 + h, play);
	char modify[] = { "编辑地图" };
	outtextxy(300 + w, 120 * 3 + h, modify);
	char search[] = { "查询时间" };
	//以上为主界面
	int flag1 = 0;
	settextstyle(45, 0, "楷体");//文字样式 高度 宽度 字体
	outtextxy(660, 560, search);
	while (1)//选择进入游戏还是编辑地图
	{
		if (MouseHit())
		{
			MOUSEMSG msg = GetMouseMsg();
			if (msg.uMsg ==WM_LBUTTONDOWN)
			{
				if (msg.x >= 300 && msg.x <= 600 && msg.y >= 120 && msg.y <= 240)//点击开始游戏
				{
					cleardevice();
					flag1 = 1;
					break;
				}
				else if (msg.x >= 300 && msg.x <= 600 && msg.y >= 360 && msg.y <= 480)//点击 编辑地图
				{
					cleardevice();
					flag1 = 2;
					break;
				}
				else if (msg.x >= 650 && msg.x <= 850 && msg.y >= 550 && msg.y <= 620)//查询时间
				{
					cleardevice();
					flag1 = 3;
					break;
				}
			}
		}
	}
	readmap();
	num_ofmap();
	if (flag1==1)//开始游戏
	{		
		start();
	}
	else if(flag1==2)//编辑地图
	{
		change();
		putimage(0, 0, &com);  
	}
	else if (flag1 == 3)
	{
		readtime();
		strcpy(t[0].s, { "第1关" });
		strcpy(t[1].s, { "第2关" });
		strcpy(t[2].s, { "第3关" });
		strcpy(t[3].s, { "第4关" });
		strcpy(t[4].s, { "第5关" });
		int ret = MessageBox(GetHWnd(), "是否排序", "提示", MB_OKCANCEL);
		if (ret == IDOK)
		{
			sort(all);
		}
		char temp[20];
		putimage(0, 0, &fir);
		for (int i = 0; i < all; i++)
		{
			rectangle(360, 90 + 120 * i, 540, 150 + 120 * i);
			sprintf_s(temp, "%s:%ds", t[i].s,t[i].ti);
			outtextxy(360, 90 + 120 * i, temp);
		}
	}
	getchar();
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值