So in my first year of college for my christmas project I needed to make a basic game using if statements, I chose a text adventure but me being a novice I chose to write out every print out:
System.out.println("You approach the two cupboards one on the right and one on the left.\nWhich one will you inspect?");
System.out.println("Please press 1 to inspect the right cupboard or 2 to press the left cupboard.");
int Action1 = 0;
while(Action1 !=1 && Action1!=2){//Checking to make sure no one puts in a number thats not 1 or 2
Action1 = in.nextInt();//Start of Player choice
if( Action1 == 1)
{
System.out.println("In the right cupboard you find a note.\nUpon reading the note it says:");
System.out.println("Hello" + " " + name + " " + "you're probably wondering why you woke up in this kitchen whith driend blood on your shirt unable to rememeber anything.\nPretty understandable. However, you're a part of my game now and I expect you to play by the rules. I'm waiting for you in the attic, if you can get here in one piece I'll reveal all.\n Ciao");
Enter = in.nextLine();
System.out.println("After reading the note you check the next cupboard.");
System.out.println("It contains a small key.\nFar too small for any of the locks in the kitchen, you keep it and move on.");
Enter = in.nextLine();
}
But now that I'm off for summer I'm trying to study some programming by myself as to not get rusty, I thought it'd be a good idea to go back to my game and clean it up by embedding the text in a text file, however theres one problem, I have absolutely no idea how to allow the user to advance the text at their own pace currently all the text just appears on screen and it looks kind of jarring. I'll include some sample code in case that helps
Scanner in = new Scanner(System.in);
FileReader file = new FileReader("C:/Users/jamie/Desktop/TextAdventure/TextFiles/Opening.txt");
BufferedReader reader = new BufferedReader(file);
String text = ""; //string to hold the text in the text file
String line = reader.readLine();
while (line != null)
{
text += line+"\n";
line = reader.readLine();
}
System.out.println(text);
I'd prefer just a nudge in the right direction instead of a full on example as I'd like to figure it out myself, but a little help would be greatful thanks!
Type Writer approach:
For the print a single line and wait x time approach. replace the code within
with