我正在制作一个基于文本的 RPG 游戏,并且正在创建一个 chooseClass 方法。见代码:
public static void classChoice(){
String cont =null;
String[] classes = {"rogue", "wizard", "knight", "archer"};
Scanner input = new Scanner(System.in);
do{
System.out.println("Choose your class (Rogue, Wizard, Knight, Archer): ");
cont = input.next();
if (cont.equalsIgnoreCase("rogue")){
System.out.println("You have chosen the Rogue!");
} else if (cont.equalsIgnoreCase("wizard")) {
System.out.println("You have chosen the Wizard!");
} else if (cont.equalsIgnoreCase("knight")) {
System.out.println("You have chosen the Knight!");
} else if (cont.equalsIgnoreCase("archer")) {
System.out.println("You have chosen the Archer!");
} else {
System.out.println("Choose a valid class!");
}
} while(!cont.equals(classes));
}
所以我为所有类创建了一个字符串数组,我认为我可以让用户输入“cont”并说虽然它不等于任何“类”数组值,然后打印消息“选择一个有效的课程!”。它不起作用,有什么想法吗?