int main()
{
int ch;
char *map_data = NULL;
menu:
if (map_data != NULL) {//if goto menu then free memory of old map
system("cls");
free(map_data);
map_data = NULL;
}
printf("选择关卡¨\n----------------------\nlevel--1 ~ 3\n----------------------\n(输入数字后按下回车)\n");
//invalid input
while ((ch = getnum()) < 1 || ch > 3) {
printf("无效输入,重新输入有效数字:");
}
reset:
if (map_data != NULL){//if goto reset then free memory of old map
system("cls");
free(map_data);
//print level
printf("#####################\n\n");
printf(" level--%d\n\n", ch);
printf("#####################\n\n");
map_data = NULL;
}
//choose a map and create it, then make a pointer "map_data" point to it.
map_data = map(ch);
//print map
prmap(map_data);
printf("\n\n按下WASD或方向键控制方向\n");
//winning condition
while (win_condition(map_data)) {
int k;
k = kbdet();
fflush(stdin);
if (!k)//back to menu
goto menu;
else if (k == 10)//reset current level
goto reset;
move(k, find_row(map_data), find_column(map_data), map_data);
Sleep(47);
system("cls");
//print level
printf("#####################\n\n");
printf(" level--%d\n\n", ch);
printf("#####################\n\n");
//print map
prmap(map_data);
//print tips
printf("\n\nESC--返回主菜单 r---重置本关\n");
}
//print completion
printf("\n -----------\n 通关了!\n -----------\n");
system("pause");
return 0;
}
无报错
而且有时使用system("cls")又可以成功清屏,我也不理解为什么了。明明是同一个exe文件
可以一个system("cls")就成功清屏吗
执行第4行,第6行的goto语句后,不会执行清屏的语句。