1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public class MapLoader {
public static void loadMap(String filePath, Map<List<Integer>, Elements> map, Mario mario, List<Personages> list) throws IOException {
ArrayList<String> lines = new ArrayList<String>();
int width = 0;
int height = 0;
Scanner reader = new Scanner(new File(filePath));
while(reader.hasNextLine()) {
String line = reader.nextLine();
lines.add(line);
width = Math.max(width, line.length());
}
height = lines.size();
for (int y=0; y < height; y++) {
String line = lines.get(y);
for (int x=0; x < line.length(); x++) {
char ch = line.charAt(x);
if (ch == 'M') {
mario = new Mario(x, height-y-1);
map.put(Arrays.asList(x,height-y-1), mario);
}
if (ch == 'E') {
Enemies enemy = new Enemies(physics, x, height-y-1);
map.put(Arrays.asList(x,height-y-1), enemy);
}
if (ch == 'T') {
map.put(Arrays.asList(x,height-y-1), new Tiles(x,height-y-1));
}
if (ch == 'C') {
map.put(Arrays.asList(x,height-y-1), new Coins(x,height-y-1));
}
}
}
}
} |
Partager