这个就是让一个笑脸在规定的通道走,可是我总是让笑脸在规定的通道里走不了,所以请各位帮忙.
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#define up 0x4800
#define down 0x5000
#define left 0x4b00
#define right 0x4d00
main()
{
int mg[13][8]={{1,1,1,1,1,1,1,1},
{1,4,1,1,1,8,1,1},
{1,8,1,1,1,8,1,1},
{1,8,8,8,8,8,1,1},
{1,1,1,1,8,8,1,1},
{1,1,8,8,8,8,1,1},
{1,1,8,1,1,1,1,1},
{1,1,8,1,1,1,1,1},
{1,1,8,8,8,8,8,1},
{1,1,1,1,1,1,8,1},
{1,1,1,1,1,1,8,1},
{1,1,1,1,1,1,3,1},
{1,1,1,1,1,1,1,1}};
int i,j;
int key,x,y;
x=2;
y=2;
for (i=0;i<13;i++)
{
textcolor(RED);
for (j=0;j<8;j++)
{
if (mg[i][j]==1)
{
gotoxy(j+1,i+1);
cprintf("%c",219);
}
if (mg[i][j]==8)
{
gotoxy(j+1,i+1);
cprintf(" ");
}
if (mg[i][j]==4)
{
gotoxy(j+1,i+1);
cprintf("%c",2);
}
if (mg[i][j]==3)
{
gotoxy(j+1,i+1);
cprintf("%c",2);
}
}
printf("\n");
}
do
{
gotoxy(x,y);
key=bioskey(0);
switch (key)
{
case up:
{
if (y-1!=1)
{
printf(" ");
y--;
gotoxy(x,y);
printf("%c",2);
}
break;
}
case down:
{
if (y+1!=1)
{
printf(" ");
y++;
gotoxy(x,y);
printf("%c",2);
}
break;
}
case left:
{
if (x-1!=1)
{
printf(" ");
x--;
gotoxy(x,y);
printf("%c",2);
}
break;
}
case right:
{
if (x+1!=1)
{
printf(" ");
x++;
gotoxy(x,y);
printf("%c",2);
}
break;
}
}
}
while (1);
}