控制台清屏闪烁的厉害
我想写一个有关推箱子的游戏,现在是人移动的代码 但是 闪烁的很厉害 怎么解决呢 #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void printMap(int map[][16])
{
int i=0,j=0;
for(i=0;i<14;i++)
{
for(j=0;j<16;j++)
{
switch(map[i][j])
{
case 0:printf("◎");
break;
case 1:printf("■");
break;
case 2:printf("★");
break;
}
if(j==15)
printf("\n");
}
}
}
void main()
{
int i,j;
char key;
int map[14][16]=
{
{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,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,0,0},
{0,0,0,0,0,0,0,0,2,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},
};
i=9 ,j=8;
while(1)
{
system("cls");
printMap(map);
key=getch();
switch(key)
{
case 72:
{
map[i-1][j]=2;
map[i][j]=0;
i--;
break;
case 75: //左箭头
map[i][j-1]=2;
map[i][j]=0;
j--;
break;
case 77: //右箭头
map[i][j+1]=2;
map[i][j]=0;
j++;
break;
case 80: //下箭头
map[i+1][j]=2;
map[i][j]=0;
i++;
break;
default:
break;
}
}
}
}