#include <stdio.h>

#include <stdlib.h>

#include <windows.h>

#include <conio.h>


#define MAZE_BOARD_HEIGHT 30

#define MAZE_BOARD_WIDTH 30

#define POINT_X 4  //보드시작좌표x

#define POINT_Y 2  //보드시작좌표y


#define LEFT 75

#define RIGHT 77

#define UP 72

#define DOWN 80


#define DELAY 100

#define EXIT 50


#define BLACK 0

#define BLUE1 1

#define GREEN1 2

#define CYAN1 3

#define RED1 4

#define MAGENTA1 5

#define YELLOW1 6

#define GRAY1 7

#define GRAY2 8

#define BLUE2 9

#define GREEN2 10

#define CYAN2 11

#define RED2 12

#define MAGENTA2 13

#define YELLOW2 14

#define WHITE 15


void textcolor(int fg_color, int bg_color)

{

SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), fg_color | bg_color<<4);

}


int Maze[MAZE_BOARD_HEIGHT][MAZE_BOARD_WIDTH]={

{'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},

{'e','0','0','0','0','0','0','0','0','0','0','1','e','0','0','0','0','0','0','0','0','0','0','1'},

{'1','0','1','1','1','1','1','0','1','1','1','1','1','0','1','1','1','1','1','0','1','1','1','1'},

{'1','0','0','0','1','0','0','0','0','0','1','1','1','0','0','0','1','1','1','0','0','0','1','1'},

{'1','0','1','0','0','0','1','0','1','0','0','1','0','0','0','1','0','0','0','0','1','1','0','1'},

{'1','0','1','1','0','1','1','0','1','1','0','0','1','0','1','0','0','1','1','0','1','0','0','1'},

{'1','1','1','0','0','0','1','1','1','0','0','1','1','1','1','0','0','1','1','1','1','0','0','1'},

{'1','0','1','0','1','1','1','0','1','0','1','1','1','0','1','0','1','1','1','0','1','0','1','1'},

{'1','0','0','0','0','0','0','0','0','0','0','0','1','0','0','0','0','0','0','0','1','0','0','1'},

{'1','1','1','1','0','1','1','1','1','1','1','1','1','0','1','0','1','1','1','1','1','1','0','1'},

{'1','1','1','1','0','1','1','1','0','0','0','0','0','0','1','1','0','0','0','0','0','1','0','1'},

{'1','1','0','0','0','0','0','1','0','1','1','1','1','0','0','0','1','0','1','1','0','1','0','1'},

{'1','0','0','1','1','1','0','1','0','1','0','0','0','0','1','1','1','0','1','1','0','1','0','1'},

{'1','0','1','1','1','0','0','0','0','1','1','1','1','0','1','1','1','0','1','0','1','0','0','1'},

{'1','0','0','0','1','1','1','0','0','0','1','1','0','0','0','0','0','0','0','0','1','0','1','1'},

{'1','0','1','0','0','1','1','0','1','1','0','1','1','0','0','1','0','1','1','0','1','0','0','1'},

{'1','0','1','1','0','1','1','0','1','0','0','0','0','0','1','0','0','0','1','0','0','1','0','1'},

{'1','0','1','0','0','1','1','1','1','0','0','1','1','1','1','0','0','1','1','1','1','0','0','1'},

{'1','0','1','0','1','1','1','0','1','0','1','0','0','1','1','1','0','1','1','0','1','1','1','1'},

{'1','0','0','0','0','0','0','0','0','0','0','0','1','0','1','1','0','0','0','0','0','0','0','x'},

{'1','0','1','1','1','1','1','1','0','1','1','0','1','0','1','0','1','0','1','1','1','1','1','1'},

{'1','0','1','0','0','0','1','1','0','1','1','1','1','0','1','0','0','0','0','0','0','0','0','1'},

{'1','0','0','0','1','0','0','0','0','0','0','1','0','0','0','1','1','1','1','0','1','1','0','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'},

};



void setCursor(int x,int y)

{

COORD pos;

pos.X=x;

pos.Y=y;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

}


COORD getCursor(void)

{

COORD curPoint;

CONSOLE_SCREEN_BUFFER_INFO pos;

GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&pos);

curPoint.X=pos.dwCursorPosition.X;

curPoint.Y=pos.dwCursorPosition.Y;

return curPoint;

}


void re0oveCursor(void)

{

CONSOLE_CURSOR_INFO cur;

GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);

cur.bVisible=0;

SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);

}


void showBoard(void)

{

int x,y;

COORD cur=getCursor();


for(y=0; y<MAZE_BOARD_HEIGHT; y++)

{

for(x=0; x<MAZE_BOARD_WIDTH; x++)

{

textcolor(10,0);

setCursor(cur.X+(x*2), cur.Y+y);

if(Maze[y][x]=='1')

printf("■");

if(Maze[y][x]=='x')


printf("→");


}

}

setCursor(cur.X,cur.Y);

}

void showCharacter(void)

{

COORD cur=getCursor();


printf("◎");

setCursor(cur.X, cur.Y);


}

int detect(int x,int y)

{

int x1=0;

int y1=0;


// 커서위치얻기

COORD cur=getCursor();


// 미로내에서의위치계산

x1=cur.X+x;

y1=cur.Y+y;

x1=x1/2-2;

y1=y1-2;


// 미로밖에있느냐

if(!((x1 >=0 && x1 <MAZE_BOARD_WIDTH) && (y1 >=0 && y1 <MAZE_BOARD_HEIGHT)))

{

return 1;

}


//배열을넘어가지않는이유

if(Maze[y1][x1]=='1')

return 1;

if(Maze[y1][x1]=='2')

return 1;

if(Maze[y1][x1]=='3')

return 1;

if(Maze[y1][x1]=='4')

return 1;

if(Maze[y1][x1]=='5')

return 1;

if(Maze[y1][x1]=='6')

return 1;


//미션성공

else if(Maze[y1][x1]=='x')

return EXIT;

else

return 0;

}

void Re0oveCharacter_Set(int x, int y)

{

int value=detect(x,y);


if(value==0)

{

COORD cur=getCursor();

printf("  ");

setCursor(cur.X+x, cur.Y+y);    

}

else if(value==EXIT)

{

setCursor(10,15);

printf("성공");

system("pause");

exit(1);

}

}



void character_static(void)

{

int kb;

setCursor(4,3);  //케릭터시작위치

while(1)

{

while(!_kbhit())

{

showCharacter();

Sleep(DELAY);

}

kb=_getch();

switch(kb)

{

case UP:

Re0oveCharacter_Set(0,-1);

break;

case DOWN:

Re0oveCharacter_Set(0,1);

break;

case RIGHT:

Re0oveCharacter_Set(2,0);

break;

case LEFT:

Re0oveCharacter_Set(-2,0);

break;

}


}

}




int main()

{

re0oveCursor(); //커서깜박이지우기

setCursor(POINT_X, POINT_Y); //보드시작좌표

showBoard(); //미로판보여주기


character_static(); //케릭터움직이기

getchar();

}



===============================================


저건 코드입니다. 

키보드 움직임을 입력받아 탈출하는 미로찾기 코드인데 

중간에 오토키같은걸 설정해서 그걸 눌르면 도중에 목적지로 움직이든

아님 첨부터 시작해서 목적지로 움직이든 자동으로 움직이는 모습을 보여지게 하고싶네요

어떻게하면좋을까요.