So I'm making a text adventure game and I'm using this code as a print method:
public static void p(String x)
{
for(int i = 0; i < x.length(); i++)
{
try
{
Thread.sleep(30);
System.out.print(x.charAt(i));
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
System.out.println("");
try
{
Thread.sleep(900);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
It basically just waits a certain amount of time before printing the next letter in a string. However, I've noticed that when players replay the game, it can sometimes get tedious to wait through the wall of text they've already read. What I need help with is making my code so that pressing enter in the middle of the method printing instantly prints the rest of the string, rather than doing one letter at a time.