For a VERY basic RPG (Well, top-down walking around game at present,) I want to make a method that reads a "save" file and stores it in memory (Saving comes later.) I'd like this save file to be user-friendly by having a way to make certain lines of it not be read by the method, so that I can put instructions on modifying it and such. Currently, the plan is to have it not read lines with a % in front, but that can change if % causes a problem.
The save format itself I'd like to have in one compressed block - one or two alphanumeric characters denote the contents of a single "tile." I don't want to simply have 169 lines for every screen of area, I'd rather have them in a compressed block of 13*13 (again, to be user-friendly.)
Essentially, how can I both a) Detect if a line starts with % b) If so, skip to next line c) If not, read two characters at a time copying to string array d) Skip blank lines
I understand BASIC IO, but I haven't been able to find a way of reading both by character and by line.
Personally, I would use a BufferedReader
to read the file line by line into individual String
objects, and inspect the contents. You can check if a line starts with a comment character by using the cunningly named String.startsWith("%")
method, and get at individual characters in the line using String.charAt(index)
, or double characters using String.substring(start, start+2)
.
Have a look at the scanner class http://docs.oracle.com/javase/tutorial/essential/io/scanning.html it should be able to do most of the work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With