用java制作一个空闲的游戏
所以,基本上,我一直在用java制作一个基于文本的游戏(这是一个激励性的游戏),我遇到了一个问题。你看,每隔一次你输入一个命令,你什么也得不到 代码如下: 导入java.util.Scanner 公营苹果{用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
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;
}
}
}
}
该代码创建以下输入命令:
0个电子。使用nextLine()或其名称。认为这可能是一个问题您没有调用
break代码>在案例“1A”
、案例“2”
和案例“3”的末尾。除此之外,目前还不清楚你在问什么。请提供一个示例输入、实际输出和预期输出代码>然后根本就没有输出!