-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.java
More file actions
47 lines (34 loc) · 867 Bytes
/
Copy pathWorld.java
File metadata and controls
47 lines (34 loc) · 867 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
import java.util.Scanner;
public class World {
private String[][][] levels;
public World() {
//get all map data and save it for later
Scanner input = new Scanner(System.in);
int count = input.nextInt();
levels = new String[count][][];
for (int lvl = 0; lvl<count; lvl++) {
int rows = input.nextInt();
int cols = input.nextInt();
input.nextLine();
setLevel (lvl, rows, cols, input);
}
}
private void setLevel(int lvl, int rows, int cols, Scanner input) {
levels[lvl] = new String[rows][cols];
input.useDelimiter("");
for (int y=0; y < rows; y++) {
for (int x=0; x < cols; x++) {
String tile = input.next();
levels[lvl][y][x] = tile;
}
input.nextLine();
}
input.reset();
}
public String[][] getLevel(int level) {
return levels[level];
}
public int getLength() {
return this.levels.length;
}
}