各位路过的请看看这个二维数组地图的问题!
现在编了一个地图,如何用getch切入?小子刚学,请不要改前面的,谢谢了!大家指点下,不胜感激! 就是让里面那个黑色的球体能在里面动起来,用getch做,该怎么做呀?在不改上面程序的基础上!谢谢各位了!
0表示路,1表是间隔物!
#include <stdio.h>
int map[30][30] =
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1},
{1,0,0,0,1,1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,1,1,1,1,1,0,1},
{1,0,1,0,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,1,0,1},
{1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,0,1,0,1},
{1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,1,0,1,0,1},
{1,0,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,0,1,0,1,0,1},
{1,0,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1},
{1,0,0,0,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1},
{1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1},
{1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1},
{1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,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nRow++)
{
for (int nLow = 0; nLow <30;nLow++)
{
switch (map[nRow][nLow])
{
case 0:
printf(" ");
break;
case 1:
printf("■");
break;
case 9:
printf("●");
break;
}
}
printf("\n");
}
}
[[it] 本帖最后由 yt22534827 于 2008-8-25 17:10 编辑 [/it]]