写项目第二天

今天就写了晚上一个小时,做的东西不是很多,已经差不多把地图做好一个了,还有终点起点的判断也写完了,然后还把地图变的精美了一些

昨天的地图

今天的地图

 就是把地图变得嘎嘎好看!

这是今天改完的代码

#include <stdio.h>
#include <easyx.h>
#include <graphics.h>
#include <math.h>
#include <conio.h>
int a=0, b=0;//控制鼠鼠的坐标,把x y看成数组下标!然后通过数组下标来画鼠鼠
int aa, bb;
int map[10][10] =
{       {0,1,1,1,1,1,1,1,1,1},
		{0,0,0,1,1,1,1,1,1,1},
		{0,1,0,0,1,0,0,0,1,1},
		{1,0,1,0,1,0,1,0,1,1},
		{1,2,1,0,0,0,1,0,1,1},
		{1,0,1,0,1,1,1,0,1,1},
		{1,0,1,0,0,0,0,0,1,1},
		{1,0,0,0,1,1,1,0,1,1},
		{1,1,1,1,1,1,1,0,0,0},
		{1,1,1,1,1,1,1,1,1,1}
};
void shuexport()
{
	if (a == 8 && b == 9)
	{
		int is_ok = MessageBox(GetHWnd(), "提示", "你真的牛", MB_OKCANCEL);
	}
}
void draw()
{
	//画图要在这个双缓冲里面
	BeginBatchDraw();
	//加载背景图片
	IMAGE img;
	loadimage(&img, "./shu.jpg", 500, 500);
	putimage(0, 0, &img);
	setfillcolor(BLACK);
	if (a>=0&&b<11&&a>=0&&b<11&&map[a][b])//如果这个点在地图上为ok那么我们就画
	{
		int drawmousex = b;
		int drawmousey = a;
		fillrectangle(50 + (30 * drawmousex), 50 + (30 * drawmousey), 50 + (30 * drawmousex) + 30, 50 + (30 * drawmousey) + 30);//把它看作鼠鼠
		aa = a;
		bb = b;
	}
	else
	{
		int drawmousex = bb;
	    int drawmousey = aa;
		fillrectangle(50 + (30 * drawmousex), 50 + (30 * drawmousey), 50 + (30 * drawmousex) + 30, 50 + (30 * drawmousey) + 30);
		a = aa;
		b = bb;
	}
	setfillcolor(RED);
	//定义墙壁的图片
	IMAGE wall;
	loadimage(&wall, "./wall.jpg", 30, 30);
	for (int i = 0; i < 11; i ++)
	{
		for (int j = 0; j < 11; j ++)
		{
			if (!map[i][j])//j表示x  i表示y
			{
				int drawx = j;
				int drawy = i;
				putimage(50 + (drawx * 30), 50 + (drawy * 30), &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);
		}
	}//画迷宫如果二维数组这个地方为0,就是通路,为1就是不通
	FlushBatchDraw();
}
void yidong()//通过全局变量x y来确定鼠鼠的移动
{
	char key = _getch();//改变的是二维数组的地方 然后我们画图再重新定义两个变量map[a][b]
		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;
		}
}
int main()
{
	initgraph(500, 500,SHOWCONSOLE);
	double x = 50, y = 50;
	while (true)
	{
		//画图
		draw();
		//控制鼠鼠移动
		yidong();
		//判断鼠鼠有没有到出口的函数
		shuexport();
	}
	getchar();
}

 明天就是把页面切换给加上,还要加上一些操作(比如墙变路什么什么的),然后就是再找几关地图,我估摸着地图要我自己写(;´༎ຶД༎ຶ`) ,明天就搞这些

下班下班

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值