这是我第一次来这里,我对编程很陌生,我已经学习 Java 2 周了,我只知道一些基础知识,所以我决定通过做一个简单的文本冒险游戏来测试我的知识,而不使用我没有的对象还没有掌握。我将继续打印故事并描述情况,并接受玩家的选择继续下去。但是我的代码有问题,如果用户输入了无效的选择,我不知道如何重复问题,我尝试了几种方法,但程序要么结束,要么给我无限循环,我需要一些帮助,请.
这是我的代码:
import java.util.Scanner;
class The_Crime {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome Stranger, Please Enter Your Name");
String name = input.nextLine();
System.out.println("Welcome" + name);
Street street = new Street();
System.out.println("You are now in the street with a dead body on the floor drowned in blood \n there is a building right ahead of you\n What would you like to do?");
String choice = input.nextLine();
while(true) {
if(choice.equals("enter building")) {
System.out.println("You have entered the empty building");
} else {
System.out.println("You are now in the street with a dead body lying around drawned in blood \n there is a building right infront of you\n What would you like to do?");
}
}
}
}