i have a bit of problem which i have run into, im trying to shorten my code for a game and i got the idea to import all the dialogue from a text file instead of hardcoding it into the code itself. however it would work if every screen only had one line to display but somescreens have more than one
if (screenCount==1)
g.drawString("Hi there!", 25,515);
if (screenCount==2)
g.drawString("Welcome to the world of Pok\u00E9mon!", 25,515);
if (screenCount==3){
g.drawString("My name is Professor BLANK!", 25,515);
g.drawString("Everyone calls me the Pok\u00E9mon Professor!", 25,540);
}
As you can see for screen one and two i could easily put the dialogue in a text file like so:
1:Hi there!
2:Welcome to the world of Pok\u00E9mon!
But for the third screen I couldnt figure out how to import it/ write it in a text file and import it
3:My name is Professor Shinwa!
Everyone calls me the Pok\u00E9mon Professor!
MORE INFO: The game only displays two lines at a time at
g.drawString("", 25,515); //the first line x and y values
g.drawString("", 25,540); // the second line x and y values
I have around 37 screens and around half or more are two lines.
Thanks for any help, much apreciated 😀
You can use the escape sequence
\nin your String as pointed in the JavaDocs:Your String could look like:
BUT I think a better solution is to put each screen text in a separate textfile. You can then read the file until no more lines are remaining and print them on the screen. The textfiles should be named with
screen#, e.g. screen1, screen2 … so you don’t need this big amount ofif-blocksin your code. Just concatenate the screen with your current screennumber and read this file, done. What if you need dialogues with response from the user? How would you handle this case?