感谢您的帮助,我认为它可能会导致无限循环。是的,如果没有完整的代码,很难发现我哪里出错了。我想将此添加为评论,但字符太多,因此我将其添加为答案。
我一直在研究我的方法,但看不出它是如何陷入无限循环的。调用 Method2 的 Method1 在确定要做什么之前必须接受用户输入。所以如果 Methpd1 调用 Method2,Method2 又调用 Method1,为什么会卡住,因为用户在任何一种方法中都有返回正常游戏的选项。这是我的方法,也许完全看到它可以阐明我哪里出错了。
FantasyGameText.gameText 方法只接受 locID 并输出该位置的对话选项。FantasyGameText.setLocation 方法是设置位置 ID 的实际方法,backSetter 方法只是将它与 gameText 方法结合起来(基本上和我开始游戏的方式相同,xAxis = 0, yAxis = 0,所以 locId = 0,即我游戏的开始部分)。
public static void backSetter(){
    if (xAxis == 2 && yAxis == 1){
        backChoice = setLocation(2, 1);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 4 && yAxis == 1){
        backChoice = setLocation(4, 1);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 2 && yAxis == 2){
        backChoice = setLocation(2, 2);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 3 && yAxis == 2){
        backChoice = setLocation(3, 3);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 4 && yAxis == 2){
        backChoice = setLocation(4, 2);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 5 && yAxis == 2){
        backChoice = setLocation(5, 2);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 1 && yAxis == 3){
        backChoice = setLocation(1, 3);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 2 && yAxis == 3){
        backChoice = setLocation(2, 3);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 3 && yAxis == 3){
        backChoice = setLocation(3, 3);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 4 && yAxis == 3){
        backChoice = setLocation(4, 3);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 2 && yAxis == 4){
        backChoice = setLocation(2, 4);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 3 && yAxis == 4){
        backChoice = setLocation(3, 4);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 4 && yAxis == 4){
        backChoice = setLocation(4, 4);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 5 && yAxis == 4){
        backChoice = setLocation(5, 4);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 3 && yAxis == 5){
        backChoice = setLocation(3, 5);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 4 && yAxis == 5){
        backChoice = setLocation (4, 5);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 30 && yAxis == 30){
        backChoice = setLocation(30, 30);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 31 && yAxis == 31){
        backChoice = setLocation(31, 31);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 50 && yAxis == 50){
        backChoice = setLocation(50, 50);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 51 && yAxis == 51){
        backChoice = setLocation(51, 51);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 52 && yAxis == 52){
        backChoice = setLocation(52, 52);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 53 && yAxis == 53){
        backChoice = setLocation(53, 53);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 54 && yAxis == 54){
        backChoice = setLocation(54, 54);
        FantasyGameText.gameText(backChoice);
    }else if (xAxis == 55 & yAxis == 55){
        backChoice = setLocation(55, 55);
        FantasyGameText.gameText(backChoice);
    }else{
        FantasyGameText.gameText(100);
    }
}
public static void menuHome(){
    boolean correctAnswer = false;
    System.out.println("");
    System.out.println("-------- CHARACTER --------");
    System.out.println("1. Inventory");
    System.out.println("2. Equip");
    System.out.println("3. Stats");
    System.out.println("4. Quests");
    System.out.println("5. Back");
    while (correctAnswer == false){
        menuChoice = userInput.next();
        System.out.println("");
        if (menuChoice.equals("1") || menuChoice.equalsIgnoreCase("inventory") || menuChoice.equalsIgnoreCase("inv")){
            correctAnswer = true;
            invMenu();
        }else if (menuChoice.equals("2") || menuChoice.equalsIgnoreCase("equip")){
            correctAnswer = true;
            equipMenu();
        }else if (menuChoice.equals("3") || menuChoice.equalsIgnoreCase("stats") || menuChoice.equalsIgnoreCase("statistics")){
            correctAnswer = true;
            statsMenu();
        }else if (menuChoice.equals("4") || menuChoice.equalsIgnoreCase("quests") || menuChoice.equalsIgnoreCase("quest")){
            correctAnswer = true;
            questMenu();
        }else if (menuChoice.equals("5") || menuChoice.equalsIgnoreCase("back") || menuChoice.equalsIgnoreCase("home")){
            correctAnswer = true;
            backSetter();
        }else{
            System.out.println("That is not a valid option, choose again,");
            menuChoice = userInput.next();
            System.out.println("");
        }
    }
return;
}
public static void invMenu(){
    boolean correctAnswer = false;
    int invList[] = new int[50];
    int itemAmount[] = new int[50];
    for (int i = 0; i <= 3; i++){
        if (healthPotionAmount > 0){
            invList[0] = 1;
            itemTempName[0] = "Health Potion x ";
            itemAmount[0] = healthPotionAmount;
        }else{
            invList[0] = 0;
        }
        if (rustySwordAmount > 0){
            invList[1] = 1;
            itemTempName[1] = "Rusty Sword x ";
            itemAmount[1] = rustySwordAmount;
        }else{
            invList[1] = 0;
        }
        if (ragsBodyAmount > 0){
            invList[2] = 1;
            itemTempName[2] = "Rags x ";
            itemAmount[2] = ragsBodyAmount;
        }else{
            invList[2] = 0;
        }
        if (chainBodyAmount > 0){
            invList[3] = 1;
            itemTempName[3] = "Chainmail Armor x ";
            itemAmount[3] = chainBodyAmount;
        }else{
            invList[3] = 0;
        }
    }
    for (int i = 0; i <= 3; i++){
        if (invList[i] > 0){
            System.out.println(itemTempName[i] + itemAmount[i]);
        }else if (invList[0] == 0 && invList[1] == 0 && invList[2] == 0 && invList[3] == 0){
            System.out.println("You have no items.");
        }
    }
    System.out.println("");
    System.out.println("1. Back");
    System.out.println("2. Home");
    menuChoice = userInput.next();
    System.out.println("");
    while (correctAnswer == false);
    if (menuChoice.equals("1") || menuChoice.equalsIgnoreCase("back") || menuChoice.equalsIgnoreCase("b")){
        correctAnswer = true;
        menuHome();
    }else if (menuChoice.equals("2") || menuChoice.equalsIgnoreCase("home") || menuChoice.equalsIgnoreCase("h")){
        correctAnswer = true;
        backSetter();
    }else{
        System.out.println("That is not a valid option, choose again.");
        menuChoice = userInput.next();
        System.out.println(""); 
    }
}