用java制作一个空闲的游戏

用java制作一个空闲的游戏,java,Java,所以,基本上,我一直在用java制作一个基于文本的游戏(这是一个激励性的游戏),我遇到了一个问题。你看,每隔一次你输入一个命令,你什么也得不到 代码如下: 导入java.util.Scanner 公营苹果{ public static int upQuarks = 0; public static int downQuarks = 0; public static int electrons = 0; public static int protons = 0; public static i

所以,基本上,我一直在用java制作一个基于文本的游戏(这是一个激励性的游戏),我遇到了一个问题。你看,每隔一次你输入一个命令,你什么也得不到

代码如下:

导入java.util.Scanner

公营苹果{

public static int upQuarks = 0;
public static int downQuarks = 0;
public static int electrons = 0;

public static int protons = 0;
public static int neutrons = 0;

public static int HAtoms = 0;

public static int upQuarkCreation = 1;
public static int downQuarkCreation = 1;
public static int electronCreation = 1;

public static int protonCreation = 1;
public static int neutronCreation = 1;

public static int atomCreation = 1;

public static String question = "0";


public static void main(String[] args) {
    Scanner dad = new Scanner(System.in);

    while(true) {

    switch(question) {

        case "0":
            System.out.println("Welcome to this untitled text adventure game, created by Adam and Benjamin Roache.");
            System.out.println("Please enter your name.");
            question = "1";
            break;

        case "01":
            dad.next();
            question = "1A";
            break;

        case "1A":
            System.out.println("\n\nAre you sure this is your name?\n[1]Yes\n[2]No");
            switch(dad.next()) {
                case "1":
                   System.out.println("Type help to get help.");
                   question = "2";
                   break;

                case "2":
                   System.out.println("\n\n");
                   question = "0";
                   break;


            }

        case "2":
            switch(dad.next()) {
                case "help":
                    if (electrons >=1 && protons >= 1) {
                        System.out.println("\n\nTo go to the Atom Creator, type atom.");

                    }
                    if (upQuarks >= 2 && downQuarks >= 2) {
                    } else {
                        System.out.println("\n\nTo create a Proton, type pro.\nTo create a Neutron, type neu.");
                        break;
                    }
                    System.out.println("\nTo create an Up Quark, type upq.\nTo create a Down Quark, type dwnq.\nTo create a electron, type el.\nTo go to your inventory, type in.");
                    break;

                case "upq":
                    upQuarks += upQuarkCreation;
                    System.out.println("\n\nYou have 1 new Up Quark.");
                    break;

                case "dwnq":
                    downQuarks += downQuarkCreation;
                    System.out.println("\n\nYou have 1 new Down Quark.");
                    break;

                case "el":
                    electrons += electronCreation;
                    System.out.println("\n\nYou have 1 new Electron.");
                    break;

                case "pro":
                    if (upQuarks >= 2 && downQuarks >= 1) {
                        protons += protonCreation;
                        upQuarks -= 2;
                        downQuarks -= 1;
                        System.out.println("\n\nYou have 1 new proton.");
                        break;
                    }else{
                        System.out.println("\n\nYou don't have those materials yet.");
                        break;
                    }

                case "neu":
                    if (downQuarks >= 2 && upQuarks >=1) {
                        neutrons += neutronCreation;
                        upQuarks -= 1;
                        downQuarks -= 2;
                        System.out.println("\n\nYou have 1 new neutron.");
                        break;
                    }else{
                        System.out.println("\n\nYou don't have those materials yet.");
                        break;
                    }

                case "atom":
                    if(protons >= 1 && electrons >=1){
                        System.out.println("\n\nWelcome to the Atom Creator!");
                        question = "3";
                        break;
                    }else{
                        System.out.println("\n\nYou can't acsess this yet.");
                        break;
                    }


                case "in":
                    if (protons >= 1 || neutrons >=1) {
                        System.out.println("\n\n" + protons + " protons, \n" + neutrons + " neutrons.");
                        break;
                    }
                    System.out.println("\n\n" + upQuarks + " up quarks, \n" + downQuarks + " down Quarks, \nand " + electrons + " electrons.");
                    break;

            }
        break;
        case "3":
            switch(dad.next()){

                case "help":
                    System.out.println("\n\nTo create an atom, type in its atomic symbol.");
                    break;

                case "H":
                    if(protons >= 1 && electrons >= 1) {
                        HAtoms += atomCreation;
                        protons -= 1;
                        electrons -= 1;
                        System.out.println("\n\nYou have created 1 new hydrogen atom.");
                        break;
                    }else{
                        System.out.println("You don't have the right materials.");
                    }
                    break;
            }
        break;
        }
    }
}
}

该代码创建以下输入命令:

  • “upq”=创建新的上夸克
  • “dwnq”=创建新的下夸克
  • “el”=产生新的电子

  • “pro”=创建新质子(当然,如果您有合适的材料。)

  • “neu”=产生新的中子

  • “atom”=输入atom创建者

  • “H”=产生一个氢原子

  • “帮助”=转到“帮助”部分

  • “in”=输入库存

    这就是所有的命令

    这是输出:

    欢迎来到这个由亚当和本杰明·罗奇创作的无标题文本冒险游戏。 请输入您的姓名。 亚当

  • 你确定这是你的名字吗? 对 [2] 没有 1. 键入help以获取帮助。 upq

    你有一个新的上夸克。 upq dwnq

    你有一个新的下夸克。 在里面 在

    1向上夸克, 1下夸克, 和0个电子。 upq dwnq

    你有一个新的下夸克。 纽 纽

    你有一个新的中子。 在里面 在

    0个质子, 1中子

    向上0夸克, 0下夸克,
    0个电子。

    使用nextLine()或其名称。认为这可能是一个问题

    您没有调用
    break
    案例“1A”
    案例“2”
    案例“3”的末尾。除此之外,目前还不清楚你在问什么。请提供一个示例输入、实际输出和预期输出然后根本就没有输出!