猫史档案馆


C++迷宫游戏

用户:C语言扩展C语言扩展查看:1 回复:2 评论:1 创建时间:2020-03-15T21:48:19


#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME)((GetAsyncKeyState(VK_NONAME)&0x8000)?1:0)
using namespace std;
int bu;
char f[11][11]/*={喵};*/={{喵,45,45,45,45,45,45,45,45,45,喵},{49,32,35,35,35,35,35,35,35,35,49},{49,32,32,32,32,32,32,32,32,32,49},{49,32,35,35,35,35,35,35,35,32,49},{49,32,35,32,32,32,32,32,32,32,49},{49,32,35,35,35,32,35,35,32,32,49},{49,32,32,32,32,32,32,32,32,35,49},{49,32,35,35,35,35,32,35,32,32,49},{49,32,35,32,32,32,32,35,32,35,49},{49,32,32,32,35,32,32,35,32,36,49},{喵,45,45,45,45,45,45,45,45,45,喵}};
bool check(char o)
{
	if(KEY_DOWN(o))
		return true;
	return false;
}
void refresh()
{
	printf("步数:%d\n",bu);
	for(int i=0;i<=10;i++)
	{
		for(int j=0;j<=10;j++)
		{
			printf("%c ",f[i][j]);
		}
		printf("\n");
	}
}
void S()
{
	printf("\n ######");
	printf("\n#      #");
	printf("\n #      #");
	printf("\n  #");
	printf("\n   #");
	printf("\n    #");
	printf("\n      #");
	printf("\n#       #");
	printf("\n #       #");
	printf("\n  ######");
}
void A()
{
	printf("\n     #     ");
	printf("\n    # #    ");
	printf("\n   #   #   ");
	printf("\n  #######  ");
	printf("\n #       # ");
	printf("\n#         #");
}
void B()
{
	printf("\n#######");
	printf("\n#      #");
	printf("\n#       #");
	printf("\n#      #");
	printf("\n#######");
	printf("\n#      #");
	printf("\n#       #");
	printf("\n#      #");
	printf("\n#######");
}
void C()
{
	printf("\n    #######");
	printf("\n   #       #");
	printf("\n  #          #");
	printf("\n #");
	printf("\n#");
	printf("\n #");
	printf("\n  #          #");
	printf("\n   #       #");
	printf("\n    #######");
}
void look(int x,int y)
{
	if(f[x][y]=='$')
	{
		f[x][y]=32;
		printf("你赢了!\n你的分数评级为:\n");
		if(bu<20)
			S();
		else if(bu<22)
			A();
		else if(bu<25)
			B();
		else
			C();
		exit(0);
	}
}
int main()
{
	int x=1,y=1;
	system("color 6");
	f[y][x]=1;
	refresh();
	while(true)
	{
		if(check('W'))
		{
			if(x>1&&f[x-1][y]!=35)
			{
				system("CLS");
				refresh();
				f[x][y]=0;
				look(x-1,y);
				f[x-1][y]=1;
				x--;
				bu++;
				Sleep(200);
			}
		}
		else if(check('A'))
		{
			if(y>1&&f[x][y-1]!=35)
			{
				system("CLS");
				refresh();
				f[x][y]=0;
				look(x,y-1);
				f[x][y-1]=1;
				y--;
				bu++;
				Sleep(200);
			}
		}
		else if(check('S'))
		{
			if(x<9&&f[x+1][y]!=35)
			{
				system("CLS");
				refresh();
				f[x][y]=0;
				look(x+1,y);
				f[x+1][y]=1;
				x++;
				bu++;
				Sleep(200);
			}
		}
		else if(check('D'))
		{
			if(y<9&&f[x][y+1]!=35)
			{
				system("CLS");
				refresh();
				f[x][y]=0;
				look(x,y+1);
				f[x][y+1]=1;
				y++;
				bu++;
				Sleep(200);
			}
		}
	}
}


回复

上一页1 页 / 共 1下一页
****************

额。。。

 

点赞0


评论


治愈绾兮治愈绾兮

为啥侦测不到按键点击?我用的dev-cpp

点赞0


评论