Currently I am trying to make a chess game, and one of the part is the save and load feature
Each chess have four data include x,y coordinate, rank and the color.
For the save feature, I use the file output method to save the data in a txt file. The first and second number is xy coordinate, and the third is color, the last is rank.
For instance, I save it like this:
"chess0816chess0618chess1712chess2614chess3415ches s3513"
But I got some problem on the load part. I know how to input the txt file but I got some problem on the loading.
The loading code is like this:
public void load() throws Exception{
File inputfile = new File ("output.txt");
Scanner input = new Scanner(inputfile);
String thisisgreat = input.next();
for (int i =0;i<=thisisgreat.length();i++){
char x = thisisgreat.charAt(i);
char y = thisisgreat.charAt(i+1);
char k = thisisgreat.charAt(i+2);
char p = thisisgreat.charAt(i+3);
if ( (x>='0'|| x<='9')&&(y>='0'|| y<='9')&&(k>='0'|| k<='9')&&(p>='0'|| p<='9')){
Chess ch ;
ch = new Chess( k, p );
GWorld.addOneObject( ch, x, y );
}
}
input.close();
}
When I run the program, it said java.lang.StringIndexOutOfBoundsException: String index out of range: 144
Can anyone help please thank you