所以,基本上,我一直在用java制作一个基于文本的游戏(这是一个像cookie clicker这样的游戏,我遇到了一个问题。你看,你键入命令的每个其他时间都没有得到任何结果。
这是代码:
import java.util.Scanner;
public class Apples {
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;
}
}
}
}
代码创建这些输入命令:
“el”=创建新电子
“pro”=创建新的Proton(当然,如果你有合适的材料。)
“neu”=创建新的Neutron
“atom”=进入Atom Creator
“H”=产生氢原子
“help”=转到帮助部分。
“in”=进入库存
这就是所有命令。
这是输出:
欢迎来到Adam和Benjamin Roache创作的这款无题文字冒险游戏。 请输入你的名字。 亚当
你确定这是你的名字吗? 1是 [2]无 1 输入帮助以获取帮助。 UPQ
你有1个新的Up Quark。 UPQ dwnq
你有1个新羽绒服。 在 在
1夸克, 1夸克, 和0电子。 UPQ dwnq
你有1个新羽绒服。 NEU neu基因
你有一个新的中子。 在 在
0质子, 1个中子。
0夸克, 0夸克, 0电子。
答案 0 :(得分:0)
使用nextLine()或它的名称。认为这可能是一个问题