「0」を入力したらバトルから逃げる処理を追加します。
これは if 〜 else if の出番です。
if (command == 1) のすぐ後ろに else if (command == 0) を足すbreak; で while を抜けるint main() {
int command;
printf("=== バトルスタート ===\n");
while (1) {
showStatus();
showEnemy();
printf("\n0: にげる\n"); // ★ 追加
printf("1: たたかう\n");
printf("コマンドを入力してください: ");
scanf("%d", &command);
getchar();
if (command == 1) {
battle();
if (enemyParam[CHAR_HP] <= 0) {
break;
}
}
else if (command == 0) { // ★ 追加:にげる処理
printf("\n%sはにげだした!\n", playerName);
break;
}
waitEnter();
}
printf("=== バトル終了 ===\n");
return 0;
}