I'm making a text based adventure game and I needed to make some user input validation.
I have the loops set up for this specific instance but I can't seem to get the loop to break after inputting the correct input.
Code:
final String KNOCK;
final String SLAM;
System.out.println("Do you politely knock on the doors or do you slam them over?");
System.out.println("Knock or Slam?");
String decisionOne = userInput.nextLine().toUpperCase();
if (decisionOne.equals("KNOCK"))
System.out.println("You politely knock on the door. After a minute you decide to push on the handle. The oak doors swing open, the old rusted iron hinges screaming into the dimly lit hallway in front of you. The Hall is roughly fifty feet long. Three doors on the East wall, and two doors on the west wall. The smell of mold, moisture, and iron hang thick in the air. What used to be a lush red carpet lines the entire length of the hallway up to a narrow set of stairs that reach up to another floor.");
else if (decisionOne.equals("SLAM"))
System.out.println("You slam into the heavy oak doors, the heavy iron hinges giving way with a pop. Dust settles around your head as you peer into the first room of The Keep. The Hall is roughly fifty feet long. Three doors on the western wall, and two doors on the eastern wall. The smell of mold, moisture, and iron hang thick in the air. What used to be a lush red carpet lines the entire length of the hallway up to a narrow set of stairs that reach up to another floor.");
else {
KNOCK = "KNOCK";
SLAM = "SLAM";
do {
System.out.println("Your options are Knock or Slam. Don't be a rude.");
decisionOne = userInput.nextLine().toUpperCase();
if (decisionOne.equals("KNOCK"))
System.out.println("You politely knock on the door. After a minute you decide to push on the handle. The oak doors swing open, the old rusted iron hinges screaming into the dimly lit hallway in front of you. The Hall is roughly fifty feet long. Three doors on the East wall, and two doors on the west wall. The smell of mold, moisture, and iron hang thick in the air. What used to be a lush red carpet lines the entire length of the hallway up to a narrow set of stairs that reach up to another floor.");
else if (decisionOne.equals("SLAM"))
System.out.println("You slam into the heavy oak doors, the heavy iron hinges giving way with a pop. Dust settles around your head as you peer into the first room of The Keep. The Hall is roughly fifty feet long. Three doors on the western wall, and two doors on the eastern wall. The smell of mold, moisture, and iron hang thick in the air. What used to be a lush red carpet lines the entire length of the hallway up to a narrow set of stairs that reach up to another floor.");
} while ((!decisionOne.equals("KNOCK")) || (!decisionOne.equals("SLAM")));
}
this is what my output looks like:
Your options are Knock or Slam. Don't be a rude.
slam
You slam into the heavy oak doors, the heavy iron hinges giving way with a pop. Dust settles around your head as you peer into the first room of The Keep. The Hall is roughly fifty feet long. Three doors on the western wall, and two doors on the eastern wall. The smell of mold, moisture, and iron hang thick in the air. What used to be a lush red carpet lines the entire length of the hallway up to a narrow set of stairs that reach up to another floor. Your options are Knock or Slam. Don't be a rude.
the problem is that if you input the correct value the first time then the code proceeds as normal. if you input the incorrect value first then try to input the correct value the loop doesn't break and continues asking for user input without moving on to the next step of the code.
Any help is much appreciated!!
Thank you