繁体   English   中英

我该如何做到这一点,while循环不会拦截到内部if语句?

[英]How do I make it so my do, while loop doesn't intercept into the inside if statements?

我正在制作基于文本的口袋妖怪游戏,并且正在尝试添加选项菜单。 我才刚刚开始,我只需要帮助弄清楚如何制作它,以便我可以调整文本速度。 现在发生的事情是,当我 go 到文本速度选项时,它会说问题,但立即 go 回到 while 循环。

public static void optionsMenu(){
    Scanner input = new Scanner(System.in);
    int optionChoice;
    String adjustTextSpeed;
    int speedChange;

    do{
        System.out.println("What would you like to check?");
        System.out.println("(1) Pokemon, (2) Item, (3) Save, (4) Option, (5) Exit");
        optionChoice = input.nextInt();
        
        if(optionChoice == 1) {
            System.out.println("Show Pokemon");
        }
        
        if(optionChoice == 2) {
            System.out.println("Show Items");
        }
        
        if(optionChoice == 3) {
            System.out.println("Coming soon");

        }
        
        if(optionChoice == 4) {
            System.out.println("Would you like to adjust text speed?");
            adjustTextSpeed = input.nextLine().toLowerCase();
            
            if(adjustTextSpeed.startsWith("y")){
                do{
                    System.out.println("Would you like the text speed to be (1) Fast, (2) Medium, or (3) Slow?");
                    speedChange = input.nextInt();
                    if(speedChange == 1) {
                        textSpeed = 1500;
                    }
                    if(speedChange == 2) {
                        textSpeed = 2000;
                    }
                    if(speedChange == 3) {
                        textSpeed = 2500;
                    }
                }while(speedChange > 3 || speedChange < 1);
            }
        }
    }while(optionChoice != 5);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM