#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void show(int arr[10][10])
{
system("cls");
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
printf("%c ",arr[i][j]);
}
printf("\n");
}
}
void changij(int arr[10][10], int *pi, int *pj, char *ch, char *oldch, char *store, char *wall, int *k, char *inwall, char *point, int mode)
{
if(*ch==*oldch)
{
if(*k==1)
{
if(mode==1 || mode==2)
{
if(*pi==0)
arr[*pi][*pj]=22;
else if(*pi==9)
arr[*pi][*pj]=21;
else
arr[*pi][*pj]=16;
}
else
{
if(*pj==0)
arr[*pi][*pj]=25;
else if(*pj==9)
arr[*pi][*pj]=23;
else
arr[*pi][*pj]=16;
}
}
else{
if(mode==1 || mode==2) arr[*pi][*pj]='-';
else
arr[*pi][*pj]='|';
}
switch (mode){
case 1 :
*store=arr[*pi][*(pj)+1];//분석
if(*store!=*wall)(*pj)++; //분석
if(*store==' ' || *store=='-') *k=0; else *k=1;
break;
case 2 :
*store=arr[*pi][*(pj)-1];//분석
if(*store!=*wall)(*pj)--; //분석
if(*store==' ' || *store=='-') *k=0; else *k=1;
break;
case 3 :
*store=arr[*(pi)-1][*pj];//분석
if(*store!=*wall)(*pi)--; //분석
if(*store==' ' || *store=='|') *k=0; else *k=1;
break;
case 4 :
*store=arr[*(pi)+1][*pj];//분석
if(*store!=*wall)(*pi)++; //분석
if(*store==' ' || *store=='|') *k=0; else *k=1;
break;
}
// if(*store==' ' || *store=='-')*k=0; else *k=1;
}//move
}//changij
int main(void)
{
char eat=' ';
char inwall=' ';
char point=15;
int arr[10][10]={
{eat,eat,eat,eat,eat,eat,eat,eat,eat,eat},
{inwall,eat,eat,eat,inwall,eat,eat,eat,eat,eat},
{inwall,eat,inwall,eat,inwall,eat,eat,eat,inwall,eat},
{inwall,eat,eat,eat,inwall,eat,eat,inwall,eat,eat},
{inwall,eat,inwall,eat,inwall,inwall,eat,eat,inwall,eat},
{eat,eat,inwall,eat,eat,eat,eat,eat,inwall,eat},
{eat,inwall,inwall,inwall,eat,inwall,inwall,eat,inwall,eat},
{eat,eat,inwall,eat,eat,inwall,inwall,inwall,inwall,eat},
{inwall,eat,inwall,inwall,eat,eat,eat,inwall,eat,eat},
{inwall,inwall,inwall,inwall,inwall,inwall,eat,eat,eat,inwall}
};
inwall='*';
int i=0, j=0;
int pi=0, pj=0;
char ch=-32;
char store=eat;
char wall=inwall;
char oldch=14;
int k=0;
arr[pi][pj]=point;
show(arr);
for(;;)
{
if(ch!=-32)
oldch=ch;
ch=getch();
if(ch==-32)
continue;
if((ch=='l' || ch==77) && pj<9)
{
point=62;
changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 1);
}//(ch=='l' || ch==77) && pj<9
if((ch=='j' || ch==75) && pj>0)
{
point=60;
changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 2);
}//if
if((ch=='i' || ch==72) && pi>0)
{
point=30;
changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 3);
}//if
if((ch=='k' || ch==80) && pi<9)
{
point=31;
changij(arr, &pi, &pj, &ch, &oldch, &store, &wall, &k, &inwall, &point, 4);
}//if
arr[pi][pj]=point;
show(arr);
}//for
system("pause");
return 0;
}