java True或false游戏在第一轮后不起作用
我是java新手,这是我开发的第一个程序。 基本上,你输入“1”,这就进入了游戏
将级别设置为1
然后,它将根据级别选择一个问题。 第一轮很好。在第一轮回答正确后,我将进入问题2
但在问题2中,如果我回答正确,它将坚持问题2并重复它,而不是转移到下一个问题
它为什么这么做?我有等级+
public static void main (String[] args) {
gameRoom();
}
public static void gameRoom() {
System.out.println("Welcome to the Truth and False game!");
System.out.println("Please write 1 to start, or -1 to exit program.");
InputI = console.nextInt();
if(InputI == 1) {
inGame = true;
gameProcess(1);
}
}
public static void gameProcess(int level) {
switch (level) {
case 1:
question = tof.getQuestion(1);
System.out.println("Your question is: " + question);
System.out.println("Please answer, true or false!.");
level = 1;
break;
case 2:
question = tof.getQuestion(2);
System.out.println("Your question is: " + question);
System.out.println("Please answer, true or false!.");
level = 2;
break;
case 3:
System.out.println("Hey1");
break;
}
while (inGame) {
InputS = console.nextLine();
while (InputS != "") {
inGame = false;
InputS = console.nextLine();
checkQuestion(level, InputS);
}
}
}
public static void checkQuestion (int level, String question)
{
Boolanswer = tof.checkQuestion(level, question);
level++;
if (Boolanswer) {
System.out.println("Correct!" + correctAnswers);
correctAnswers++;
} else {
System.out.println("Incorrect! " + correctAnswers);
}
inGame = true;
gameProcess(level);
}
问题可能是,输入时系统无法读取循环!=“”但我可能错了,这是另一门课:
private String[][] questionsArray = new String[][]
{
{"Is sky blue?", "true"},
{"Is sky green?", "false"}
};
private String answer = "";
private String Currentanswer = "";
private String question = "";
private int level = 0;
private boolean returnValue = false;
public String getQuestion(int Level) {
switch (Level) {
case 1:
question = questionsArray[0][0];
break;
case 2:
question = questionsArray[1][0];
break;
}
return question;
}
public String getAnswer(int Level) {
switch (Level) {
case 1:
answer = questionsArray[0][1];
break;
case 2:
answer = questionsArray[1][1];
break;
}
return answer;
}
public boolean checkQuestion(int level, String answer) {
switch (level) {
case 1:
Currentanswer = questionsArray[0][1];
if (Currentanswer.equalsIgnoreCase(answer)) {
returnValue = true;
} else {
returnValue = false;
}
break;
case 2:
Currentanswer = questionsArray[1][1];
if (Currentanswer.equalsIgnoreCase(answer)) {
returnValue = true;
} else {
returnValue = false;
}
break;
}
return returnValue;
}
问题是,当我正确回答第二个问题时,它不会打印任何内容。如果我回答不正确,就会转到第一个问题
我知道我只有两个问题,但我只是在测试。级别应该是3,然后打印“嘿!”根据开关的情况
共 (0) 个答案