I am making a simple text based card game for fun/practice with parsing files. I have a plain text file with all the specs for the card. My cards are split with "##########". They are multilined. For now I simply want to be able to pull up the entirety of any ONE card whenever I want. For example, Player picks character 1, so I pull up Card 1 Only? How ?
EXAMPLE:
##########
CARD 1
Character Name:
Something Else:
##########
CARD 2
Character Name:
Something Else:
##########
Character Name:
Something Else:
##########
HOW CAN I ACTUALLY SPLIT THE CARDS SO THAT I CAN JUST ASK THE USER WHICH CARD. I don't want to have to read the lines and print the way I did. It is rather cumbersome and convoluted. My NEW ATTEMPT: ArrayList listForCard1 = new ArrayList(); Integer selected_card = 1;
try {
String line;
FileReader fR = new FileReader("MyText.txt");
BufferedReader br = new BufferedReader(fR);
int x = 0;
Integer card = 1;
while ((line = br.readLine()) != null) {
ALines[x] = line;
x++;
if (line.contains("##########")) {
if ( card == selected_card) {
listForCard1.add(br.readLine());
// System.out.println(br.readLine());
break;
} else {
card++;
}
}
}
System.out.println("Done");
System.out.println(ALines[0]);
System.out.println(ALines[1]);
System.out.println(ALines[2]);
System.out.println(ALines[3]);
System.out.println(ALines[4]);
System.out.println(ALines[5]);
System.out.println(ALines[6]);
} catch (IOException e) {
e.printStackTrace();
}
}