我想實現一個有關卡的游戲,在贏得當前關卡后,用戶可以解決另一個問題。我使用枚舉數據為每個循環做到了這一點。如果您有其他解決此問題的方法,請與我分享。程序在用戶做出正確決定后已經改變了級別,但我想實現如果用戶提供錯誤答案,它會退出主循環。我試圖通過break運營商解決它,但它不起作用。如果您對此問題有其他解決方案,請與我分享。static void levelchanger() { Levelinfo[] types = Levelinfo.values(); for (Levelinfo arr : types) { while (arr.moves != 0 && arr.display != arr.goal) { System.out.println("It is " + arr + " level. You have: " + arr.moves + " moves. Goal: " + arr.goal); System.out.println("Step: 1) " + arr.gnumbers[0] + " 2) " + arr.gnumbers[1]); Scanner in = new Scanner(System.in); int action = in.nextInt(); switch (action) { case 1: arr.display += arr.gnumbers[0]; System.out.println("Result: " + arr.display); break; case 2: arr.display += arr.gnumbers[1]; System.out.println("Result: " + arr.display); break; } arr.moves--; if (arr.moves == 0 && arr.display != arr.goal) { System.out.println("You don't have more moves!"); break; } else if (arr.display == arr.goal) { System.out.println("Alright! Next level"); } } }}
添加回答
舉報
0/150
提交
取消