텍스트 어드벤처 게임을 만들고 프로그램이 종료되었습니다. 왜 누군가가 도움을 줄 수 있는지 확인하지 못합니까? 정말 바보 같은 실수를해서 미안해, 나는 초보자이다. 감사합니다 :)Java; Statement로 종료 된 코드
//Set up scanner "userInput"
System.out.println("You are in a room");
myScanner = new Scanner(System.in);
String userInput = myScanner.nextLine();
//Variables
int bone = 0;
int flashlight = 0;
//Begin Adventure
if (userInput.equalsIgnoreCase("look")
|| userInput.equalsIgnoreCase("look around")
|| userInput.equalsIgnoreCase("obsererve surroundings")) {
System.out.println(
"There are 4 doors; one is blue, one is green, one is red, and one is yellow");
} else {
System.out.println("You cant do that");
}
if (userInput.equalsIgnoreCase("enter blue door")
|| userInput.equalsIgnoreCase("enter blue room")
|| userInput.equalsIgnoreCase("go into blue door")
|| userInput.equalsIgnoreCase("go into blue room")) {
System.out.println("The room is pitch black");
if (flashlight == 1) {
if (userInput.equalsIgnoreCase("use flashlight")
|| userInput.equalsIgnoreCase("use flash light")) ;
System.out.println("Light! You can see a bone on a table.");
if (userInput.equalsIgnoreCase("take bone") || userInput.equalsIgnoreCase("grab bone")) ;
}
if (userInput.equalsIgnoreCase("leave room")
|| userInput.equalsIgnoreCase("exit room")
|| userInput.equalsIgnoreCase("exit")) ;
System.out.println("You return to the central room.");
}
if (userInput.equalsIgnoreCase("enter red door")
|| userInput.equalsIgnoreCase("go through red door")
|| userInput.equalsIgnoreCase("enter red room")
|| userInput.equalsIgnoreCase("enter red room")) {
System.out.println("There is a man sitting in the chair");
}
if (userInput.equalsIgnoreCase("talk to man") || userInput.equalsIgnoreCase("talk")) {
System.out.println("He tells you that you need to go to the yellow room");
}
if (userInput.equalsIgnoreCase("leave room")
|| userInput.equalsIgnoreCase("exit room")
|| userInput.equalsIgnoreCase("exit")) {
System.out.println("You return to the central room");
}
if (userInput.equalsIgnoreCase("enter yellow door")
|| userInput.equalsIgnoreCase("enter yellow room")
|| userInput.equalsIgnoreCase("go into yellow door")
|| userInput.equalsIgnoreCase("go into yellow room")) {
System.out.println("There is a flashlight on a table");
}
if (userInput.equalsIgnoreCase("take flashlight")
|| userInput.equalsIgnoreCase("grab flashlight")
|| userInput.equalsIgnoreCase("take flash light")
|| userInput.equalsIgnoreCase("grab flash light")) {
System.out.println("You got that flashlight man");
}
'String userInput = myScanner.nextLine()'이라는 줄로 한 번만 사용자 입력을 요구합니다. 루프를 반복하여 사용자에게 메시지를 표시해야합니다. 당신이 자바 프로그래밍에 익숙한가요? 그렇다면 게임을 작성하기 전에 자바와 프로그래밍에 익숙해지기를 원할 것입니다. –
어딘가에'userInput = userInput.toLowerCase();'라고 써서 모든 곳의 'equalsIgnoreCase' 대신'equals'를 사용하면됩니다. –