I'm trying to make a short game where the player has to open a treasure chest and buy stuff from a shop, but when i exit the shop, it tells me "Invalid command. Use "shop" or "open."" I added the "end of loop" and found out that after store is finished, it ends the loop and ignores the nextLine() command and goes directly to the if-else ladder. Can anyone help me solve this?
while (win == 0)
{
opt = s.nextLine();
er = 1;
if (opt.equalsIgnoreCase("shop"))
{
store();
er = 0;
}
else if (opt.equalsIgnoreCase("open"))
{
gold += open();
}
else if (opt.equalsIgnoreCase("exit"))
{
return;
}
else if (er == 1)
{
System.out.println("Invalid command. Use \"Shop\" or \"Open.\"");
wait (1);
}
if (gold >= 1000000)
{
win = 1;
}
System.out.println ("End of loop");