马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
char snakeDraw[SNAKEMAP][3];
int snakemap[21][28] = { {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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,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,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,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,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,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,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,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,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,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,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,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,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,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,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,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,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,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,0,0,0,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,}};
void randsnake()
{
int y = -1,
x = -1;
srand((unsigned)time(NULL));
x = rand() % 19 + 1;
y = rand() % 24 + 1;
snakeDraw[0][0] = y;
snakeDraw[0][1] = x;
snakeDraw[0][2] = to_west;
snakeDraw[1][0] = y;
snakeDraw[1][1] = x + 1 ;
snakeDraw[1][2] = to_west ;
snakeDraw[2][0] = y;
snakeDraw[2][1] = x + 2;
snakeDraw[2][2] = to_west;
int i = 0;
for( i = 0; snakeDraw[i][0] != 0; i++)
{
strncpy(&snakemap[snakeDraw[i][0]][snakeDraw[i][1]], '*' ,1);
}
}
void snakemaap()
{
int i,j ;
for( i = 0 ;i < 21; ++i)
{
for( j = 0; j < 28; ++j)
{
if(snakemap[i][j]==1)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
}
int main()
{
while(1)
{
system("cls");
snakemaap();
_sleep(1000);
}
randsnake();
system("pause");
return 0;
}
是这个代码出问题了吗?为啥在snakemap数组里面没有。
void randsnake()
{
int y = -1,
x = -1;
srand((unsigned)time(NULL));
x = rand() % 19 + 1;
y = rand() % 24 + 1;
snakeDraw[0][0] = y;
snakeDraw[0][1] = x;
snakeDraw[0][2] = to_west;
snakeDraw[1][0] = y;
snakeDraw[1][1] = x + 1 ;
snakeDraw[1][2] = to_west ;
snakeDraw[2][0] = y;
snakeDraw[2][1] = x + 2;
snakeDraw[2][2] = to_west;
int i = 0;
for( i = 0; snakeDraw[i][0] != 0; i++)
{
strncpy(&snakemap[snakeDraw[i][0]][snakeDraw[i][1]], '*' ,1);
}
} |