求大神指教,怎么才能在运行的时候按WASD上面的符号还保留着
#include<stdio.h>#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
int x=20,y=20;
char key;
int map[20][20];
int i,j,m,n=5;
void gotoxy(int x,int y);
void draw(int x,int y);
int ix,iy;
void setmap()
{
srand((unsigned)time(NULL));
for(m=0;m<5;m++)
{
ix=rand()%20+1;
iy=rand()%20+1;
gotoxy(ix+1,iy+1);
printf("$");
}
}
void draw(int x,int y)
{
system("cls");
for(m=0;m<5;m++)
{gotoxy(ix,iy);printf("$");}
gotoxy(x,y);
printf("&");
}
void gotoxy(int x,int y)
{
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos={x,y};
SetConsoleCursorPosition(hOut,pos);
}
int main()
{
draw(x,y);
setmap();
while(1)
{
if(kbhit())
{ key=getch();
switch(key)
{
printf("%d\n",key);
case 'w':{draw(x,--y>=0?y:0);break;}
case 's':{draw(x,++y<=64?y:64);break;}
case 'd':{draw(++x<=64?x:64,y);break;}
case 'a':{draw(--x>=0?x:0,y);break;}
}
}
}
}