スロット マシン シミュレーター用のプログラムを書いていますが、ほとんどのコードは while ループにあります。
System.out.println(" * Choose an option: * ");
System.out.println(" * 1: Display credit count. * ");
System.out.println(" * 2: Play Again. * ");
System.out.println(" * 3: End Game. ");
ユーザーがゲームを終了するために3を選択すると、ゲーム終了メニューに移動します。ユーザーがクレジットがなくなったためにループを離れたのか、それともゲームを終了することを選択したのかを判断するために、私のループの外に
別のステートメントのグループがあります。if
while
//The case in which the user ended the game.
else {
System.out.println("");
System.out.println("You have ended the game. You have finished with a total of: "+credits+" credits!");
System.out.println("");
System.out.println("Next player?");
System.out.println("");
System.out.println("1: Yes, there is another player that would like to start with my "+credits+" credits.");
System.out.println("2: Yes, there is another player, but he will start with 10 credits.");
System.out.println("3: No, End the game.");
selection2 = in.nextInt();
}
私がやろうとしているのは、ユーザーが1を入力すると、メインのゲームループの最初に戻ることです。
goto cmdがないことは理解していますが、これを行う方法を知っている人はいますか? ループの外側で立ち往生していて、ループに戻ることができません! (すべての外に別のループを作ることを考えました...)