int[][] map = {
{1,1,2,2,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,2,2,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
int mapWidth = 20;
int mapHeight = 15;
File file = new File("maps/map1.txt");
Scanner sc;
for(int x = 0; x < mapWidth; x++) {
for(int y = 0; y < mapHeight; y++) {
try {
sc = new Scanner(file);
while(sc.hasNextLine()) {
String i = sc.nextLine();
map[y][x] = Integer.parseInt(i);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
This code is supposed to load the tile id’s from a text file. Which it does. The String i is actually set to each individual number in the text file. Then, at the end of the file the map gets set to the entire map of only the last id. Why is that? I tried to trouble shoot it and figure it out but I couldn’t. What do you guys think?