-4
我想得到一個結果,如果我使用for循環然後'怪物'出來10次。但'怪物'不斷出來。你能告訴我問題是什麼? 感謝您閱讀到最後:)循環不出來
private static void fight() {
for(int i=0; i<10; i++) {
while (user.isalive() && enemy.isalive()) {
user.attack(enemy);
if (!enemy.isalive()) break;
enemy.attack(user);
System.out.println("------------------------------");
}
if (user.isalive()) {
System.out.println("The monster is dead.");
System.out.println("------------------------------");
user.money+=enemy.money;
// System.out.println(player.money);
System.out.println("I got 100 won");
System.out.println("total won : "+user.money+"won");
enemy.hp=50;
}
else {
System.out.println("I'm dead and the game is over.");
break;
}return;
}
}
我已經低估了這個問題,因爲沒有任何證據表明此代碼執行任何調試。請[編輯]您的問題,向我們展示您的調試未發現的內容,以及關於特定代碼行的具體問題。請參閱:[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)和[如何調試小程序](https://ericlippert.com/2014/03/05 /如何調試的小程序/)。 –