我想实现一个有关卡的游戏,在赢得当前关卡后,用户可以解决另一个问题。我使用枚举数据为每个循环做到了这一点。如果您有其他解决此问题的方法,请与我分享。程序在用户做出正确决定后已经改变了级别,但我想实现如果用户提供错误答案,它会退出主循环。我试图通过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
提交
取消
