类似贪吃蛇的问题 求指导
#include<stdio.h>#include<stdlib.h>
#define M 15
#define N 15
void dayin(int b[M][N])
{
int i , j;
for(i = 0;i < M;i++)
{
for(j = 0; j < N; j++)
{
switch(b[i][j])
{
case 0: printf(" "); break;
case 1: printf(" o"); break;
case 2: printf(" $"); break;
case 3: printf(" |"); break;
}
}
printf("\n");
}
printf("\n请输入要走的方向并按回车确认(w,s,a,d一次代表上下左右:)");
}
/*int isOK(int m, int n)
{
}*/
void main()
{
int b[M][N] =
{
{2,0,0,3,0,1,3,1,0,3,1,0,0,1,3},
{0,3,1,0,0,3,0,0,1,0,0,1,3,1,3},
{0,1,0,0,3,0,0,1,0,3,3,1,0,0,3},
{3,0,3,0,1,0,3,1,0,1,3,3,1,0,3},
{0,1,0,0,3,0,0,1,0,3,0,1,3,1,3},
{1,0,0,3,0,1,3,1,0,3,1,0,0,3,3},
{0,3,1,0,0,3,0,0,1,0,3,0,1,0,3},
{1,0,0,3,0,1,3,1,0,3,0,1,3,1,3},
{0,3,1,0,0,3,0,0,1,0,0,3,0,1,3},
{1,0,0,3,0,1,3,1,0,3,1,0,0,1,3},
{0,3,1,0,0,3,0,0,1,0,0,1,3,1,3},
{0,1,0,0,3,0,0,1,0,3,3,1,0,0,3},
{3,0,3,0,1,0,3,1,0,1,3,3,1,0,3},
{0,1,0,0,3,0,0,1,0,3,0,1,3,1,3},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
};
int m=0,n=0,h;
char w,s,a,d,ch;
dayin(b);
while(1)
{
scanf("%c",&ch);
switch(ch)
{
case 'w':
m=m-1;
n=n;
h=b[m][n];
if(m<0||n<0||n>15)
{
b[0][0]=0;
printf("\n你死了\n");
}
else if(h==0)
{
b[m+1][n]=0;
b[m][m]=2;
}
else if(h==1)
{
b[m+1][n]=0;
b[m][m]=2;
}
else if(h==3)
{
system("cls");
printf("\n你死了\n");
}
break;
case 's':
m=m+1;
n=n;
h=b[m][n];
if(m>15||n<0||n>15)
{
b[0][0]=0;
printf("\n你死了\n");
}
else if(h==0)
{
b[m-1][n]=0;
b[m][n]=2;
}
else if(h==1)
{
b[m-1][n]=0;
b[m][n]=2;
}
else if(h==3)
printf("\n你死了\n");
break;
case 'a':
m=m;
n=n-1;
h=b[m][n];
if(n<0||m<0||m>15)
{
b[0][0]=0;
printf("\n你死了\n");
}
else if(h==0)
{
b[m][n+1]=0;
b[m][n]=2;
}
else if(h==1)
{
b[m][n+1]=0;
b[m][n]=2;
}
else if(h==3)
{
system("cls");
printf("\n你死了\n");
}
break;
case 'd':
m=m;
n=n+1;
h=b[m][n];
if(n>15||m<0||m>15)
{
b[0][0]=0;
printf("\n你死了\n");
}
else if(h==0)
{
b[m][n-1]=0;
b[m][n]=2;
}
else if(h==1)
{
b[m][n-1]=0;
b[m][n]=2;
}
else if(h==3)
{
system("cls");
printf("\n你死了\n");
}
break;
}
}getch();
}
我实现不了哪错了 我想实现在一个界面上移动 指点下