我已经声明了一个 id 和描述的枚举以及坐标的双数组。
public enum Location {
GRASS(0, "Green Grass"),
CHURCH(1, "A church");
private int locationId;
public int locationId() { return locationId; }
private String description;
public String details(){ return description; }
Location(int locationId, String description){
this.locationId = locationId;
this.description = description;
}
然后我宣布了我的位置数组......
private Location[][] locations;
然后我为我的地图的宽度和高度设置了一些随机位置......
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
locations[x][y] = Math.random() < 0.5 ? Location.GRASS: Location.CHURCH;
}
}
现在我想遍历一组位置并从tiles [x] [y]中提取locationId
int locationID;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
locationID = locations[x][y].WHATGOESHERE?
Debug.e("Current location: " + locationID);
}
}
此时如何拉回 Location 的第一个元素?我想要那个特定位置在 x y 处的数值。
干杯!