0

スロット マシン シミュレーター用のプログラムを書いていますが、ほとんどのコードは 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を選択すると、ゲーム終了メニューに移動します。ユーザーがクレジットがなくなったためにループを離れたのか、それともゲームを終了することを選択したのかを判断するために、私のループの外に
別のステートメントのグループがあります。ifwhile

//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がないことは理解していますが、これを行う方法を知っている人はいますか? ループの外側で立ち往生していて、ループに戻ることができません! (すべての外に別のループを作ることを考えました...)

4

3 に答える 3

0

あなたができることは、と呼ばれるメソッドを作成することですgoToLoop()

そのメソッド内にループのすべてのコードを配置するため、ループに戻りたい場合は、単に呼び出しますgoToLoop()

それが役立つことを願っています

于 2014-11-07T11:28:29.867 に答える