File Parser for levels #18

Merged
tonitch merged 29 commits from MapParser into master 2023-04-21 20:00:16 +02:00
2 changed files with 29 additions and 3 deletions
Showing only changes of commit 1cd017f8ca - Show all commits

View File

@ -27,9 +27,16 @@ public class MapParser {
}
}
byte[] map_data = Arrays.copyOfRange(bytes, start_position, end_position); //TODO tonitch cursor
byte[] level_data = Arrays.copyOfRange(bytes, start_position, end_position);
int width_map = level_data[0], height_map = level_data[1];
byte[] map_data = Arrays.copyOfRange(level_data, 2, 2 + width_map * height_map / 8 + (height_map * width_map % 8 != 0 ? 1 : 0));
byte piece_count = level_data[3 + width_map * height_map / 8 + (height_map * width_map % 8 != 0 ? 1 : 0)];
byte[] pieces_datas = Arrays.copyOfRange(level_data, 4 + width_map * height_map / 8 + (height_map * width_map % 8 != 0 ? 1 : 0), level_data.length-1);
for (int piece_index = 0; piece_index < piece_count; piece_index++) {
}
fileStream.close();
return new Map(); //TODO: Send the parsed map
}
@ -37,6 +44,12 @@ public class MapParser {
// public static void SaveMapFile(File file){
// }
private static boolean[][] BuildMatrixFromBytes(int map_width, int map_height, byte[] map_data){
boolean[][] ret = new boolean[map_height][map_width];
//TODO tonitch: cursor 2
}
public static void main(String[] args) throws IOException, IllegalAccessException {
ParseMapFile(new File("test.smap"));
}

View File

@ -2,7 +2,7 @@ package school_project;
public class Shape {
protected boolean[][] matrix;
protected int height, width;
@ -37,4 +37,17 @@ public class Shape {
public boolean[][] getShape() {
return matrix;
}
}
@Override
public String toString() {
String ret = "";
for (boolean[] row : matrix) {
for (boolean el : row) {
if(el) ret = ret.concat("");
else ret = ret.concat("");
}
ret = ret.concat("\n");
}
return ret;
}
}