ncurses에 대한 조언 부탁드립니다~
일단 본문 소스를 보여드릴께요~
#include 
#include 
#include 
#include 
#include 
#define YMAX 10
#define XMAX 30
int arry[YMAX][XMAX]={{0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,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,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
					    {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
					    {0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
					    {0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
					    {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
					    {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
					    {0,0,0,0,0,0,0,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
					    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
typedef struct _node{																			//데큐를 구현할 노드
		int X;
		int Y;
		struct _node *prev;
		struct _node *next;
}node;
node *head, *tail;
int startx=0, starty=2;																			//시작을 포인터를 알리기위한 변수 두개
int count=0;
int sum = 0;
void print(void)
{
	WINDOW **mywin;
	int i,j;
	int y,x;
	initscr();
	start_color();
	init_pair(1,COLOR_BLACK,COLOR_RED);
	init_pair(2,COLOR_BLACK,COLOR_BLUE);
//	init_pair(2	,COLOR_RED,COLOR_BLACK);
	keypad(stdscr,TRUE);
	mywin = (WINDOW **)malloc(300*sizeof(WINDOW *));
	for (i=0 ; i < YMAX ; i++)
	{
		y=(i*3)+5;
		for (j=0 ; j < XMAX ; j++)
		{
			if (arry[i][j] == 0)
			{
				x = (j*3)+20;
				mywin[sum] = subwin(stdscr, 3, 3, y, x);						//메뉴바윈도우 생성				
				wborder(mywin[sum], '|', '|', '-', '-', '+', '+', '+', '+'); 	
				wrefresh(mywin[sum]);
			}
			else if (arry[i][j] == 1)
			{
				x = (j*3)+20;
				mywin[sum] = subwin(stdscr, 3, 3, y, x);						//메뉴바윈도우 생성				
				wattron(mywin[sum],COLOR_PAIR(1));		
				wattron(mywin[sum],A_REVERSE);			
				wborder(mywin[sum], '|', '|', '-', '-', '+', '+', '+', '+'); 	
				wattroff(mywin[sum],COLOR_PAIR(1));	
				wattroff(mywin[sum],A_REVERSE);					
				wrefresh(mywin[sum]);
			}	
			else if (arry[i][j] == 3 || arry[i][j] == 8)
			{
				x = (j*3)+20;
				mywin[sum] = subwin(stdscr, 3, 3, y, x);						//메뉴바윈도우 생성				
				wattron(mywin[sum],COLOR_PAIR(2));		
				wattron(mywin[sum],A_REVERSE);			
				wborder(mywin[sum], '|', '|', '-', '-', '+', '+', '+', '+'); 	
				wattroff(mywin[sum],COLOR_PAIR(2));	
				wattroff(mywin[sum],A_REVERSE);					
				wrefresh(mywin[sum]);
			}	
			sum += 1;
		}
	}
	sum = 0;
	for (i=0;i
	{
		for (j=0;j
		{
			wrefresh(mywin[sum]);
			sum += 1;
		}
	}
	sum = 0;
	for (i=0;i
	{
		for (j=0;j
		{
			delwin(mywin[sum]);
			sum += 1;
		}
	}
	free(mywin);
	endwin();
}
/*데큐 초기화*/
void init_node(void)
{
	head = (node*)malloc(sizeof(node));
	tail = (node*)malloc(sizeof(node));
	head->next = tail;
	head->prev = head;
	tail->prev = head;
	tail->next = tail;
}
/*막다른길이 있을때 되돌아가는 함수*/
void pop_stack(void)
{
	node *t;						//삭제하고 그 노드를 물릴 포인터변수
	int i;
	if (head->next==tail)			//head->next가 tail를 가르키면 언더플러
		return;
	t = head->next;
	head->next=t->next;
	for (i=0;i<1;i++)
	{
		if (arry[starty-1][startx]==3)									//현위치 바로 위
		{
			arry[starty][startx]=8;
			starty--;
		}
		else if (arry[starty][startx+1]==3)								//현위치 바로 오른쪽
		{
			arry[starty][startx]=8;
			startx++;		
		}
		else if (arry[starty+1][startx]==3)								//현위치 바로 아래쪽
		{
			arry[starty][startx]=8;
			starty++;		
		}
		else if (arry[starty][startx-1]==3)								//현위치 바로 왼쪽
		{
			arry[starty][startx]=8;
			startx--;		
		}
	}
	count--;
	free(t);
}
/*앞에 길이 막히지 않았을때 가는 함수*/
void put_queue(void)
{
	node *t;
	t = (node*)malloc(sizeof(node));
	if (t == NULL)
		exit(1);
	t->next=head->next;
	t->prev=head;
	head->next=t;
	head->next->next->prev=t;
	t->X=startx;
	t->Y=starty;
	count++;
}
/*앞에 길이 막히지 않았을때 가고 흔적을 남기고 메모리 삭제하는 함수*/
void get_queue(void)
{
	node *t;
	t=tail->prev;
	if (t==head)
		return;
	tail->prev=t->prev;
	t->prev->next=tail;
	printf("(%3d,%3d)\n",t->Y,t->X);
	free(t);
}
/*제일 끝에 메모리 삭제하는 함수*/
void clear_queue(void)
{
	node *t;
	node *s;
	t = head->next;
	while (t!=tail)
	{
		s = t;
		t = t->next;
		free(s);
	}
	head->next=tail;
	tail->prev=head;
}
/*우선순위를 결정해서 이동하는 함수*/
void operator(void)
{
	int i,j;
	while (1)
	{
		if (starty == 0)
			break;
		if (arry[starty-1][startx]==1)									//현위치 바로 위
		{
			put_queue();
			arry[starty][startx]=3;
			starty--;
		}
		else if (arry[starty][startx+1]==1)								//현위치 바로 오른쪽
		{
			put_queue();
			arry[starty][startx]=3;
			startx++;		
		}
		else if (arry[starty+1][startx]==1)								//현위치 바로 아래쪽
		{
			put_queue();
			arry[starty][startx]=3;
			starty++;		
		}
		else if (arry[starty][startx-1]==1)								//현위치 바로 왼쪽
		{
			put_queue();
			arry[starty][startx]=3;
			startx--;		
		}
		else if (arry[starty-1][startx]!=1&&arry[starty][startx+1]!=1&&arry[starty+1][startx]!=1&&arry[starty][startx-1]!=1)
			pop_stack();
		print();
/*		for (i=0 ; i
		{
			for (j=0 ; j
			{
				printf("%d",arry[i][j]);
			}
			printf("\n");
		}*/
		usleep(30000);
	}
}
int main(void)
{
	int i;
	init_node();
	initscr();
	start_color();
	curs_set(0);
	operator();
	for (i=0;i<=count;i++)
		get_queue();	
	clear_queue();
	free(head);
	free(tail);	
	endwin();
	return 0;	
}
/*여기서 질문입니다~ 꼭 좀 답변 부탁 드릴께요~ 실행을 시키보시면 알다시피 ncurses에서 실행이 잘 안되네요
 그냥 콘솔화면에서는 잘돌아갑니다 근데 이늠이 ncurses에서만 유독 안돌아갑니다 혹시 동적 메모리 관리를 잘못해줬는지 
 모르겠네요 시원한 답변 기다릴께요 ㅜ.ㅜ */


댓글 달기