I don't understand your last sentence. Why does it make an array for every DungeonRoom ?
public class HostileArea extends Location {
private String naam,filename,image,dungeonMap;
File story;
protected DungeonRoom[][] dungeon;
private int ID;
private int[] startPos;
public HostileArea(Integer id,Integer x,Integer y,String name,String filename,String image,String dungeonMap){
ID = id.intValue();
positie[0] = x;
positie[1] = y;
naam = name;
this.image = image;
this.filename = filename;
story = new File(this.filename);
this.dungeonMap = Global.rwtext.getContents(new File("Data/DungeonMaps/" + dungeonMap));//
buildMap();
}
public void buildMap(){
//get # rows and columns
String[] lines = dungeonMap.split(System.getProperty("line.separator"));
int numLines = lines.length;
int width = 0;
for(String str: lines){
if(str.length() > width) width = str.length();
}
dungeon = new DungeonRoom[width][numLines];
// here each of them gets initialized according to their type, be it forest, dungeon or whatever
}
public class DungeonRoom extends HostileArea{
String type = null;//forest, dungeon, path
DungeonEvent event = null;
Enemy mob;
int[] position;
public DungeonRoom(){
}
public DungeonRoom(String type,Enemy mob, DungeonEvent event,int[] position){
this.type = type;
this.mob = mob;
this.event = event;
this.position = position;
}
public void enter(String origin){
if(mob != null){
//mob present, combat
}
if(event != null){
//play dungeon event
}
else{
//just road
// 1) check for crossroad
for(int j=-1;j<2;j++){
for(int k=-1;k<2;k++){
if(dungeon[position[0] + j][position[1] + k].getType().equalsIgnoreCase("path") && k!=0 && j!=0){
RPGMain.printText(true,"Go to the " + Town.getDirection(j, k) + ".");
}
}
}
// 2) check to see enemies ahead (difference day/night)
if(Global.day){
// can only see ahead during the day
//origin is THE DIRECTION YOU CAME FROM, ie coming from the east -> you went to the west
for(int j=-1;j<2;j++){
System.out.println("Testing see enemies");
if(origin.equalsIgnoreCase("south")){
if(dungeon[position[0]+j][position[1]+1].hasMob()){
RPGMain.printText(true, "To the " + Town.getDirection(j, 1) + " you see an " + dungeon[position[0]][position[1]+1].getMob().getNaam()+ ".");
}
}
if(origin.equalsIgnoreCase("north")){
if(dungeon[position[0]+j][position[1]-1].hasMob()){
RPGMain.printText(true, "To the " + Town.getDirection(j, -1) + " you see an " + dungeon[position[0]][position[1]-1].getMob().getNaam()+ ".");
}
}
if(origin.equalsIgnoreCase("east")){
if(dungeon[position[0]-1][position[1]+j].hasMob()){
RPGMain.printText(true, "To the " + Town.getDirection(-1, j) + " you see an " + dungeon[position[0]-1][position[1]].getMob().getNaam()+ ".");
}
}
if(origin.equalsIgnoreCase("west")){
if(dungeon[position[0]+1][position[1]+j].hasMob()){
RPGMain.printText(true, "To the " + Town.getDirection(1, j) + " you see an " + dungeon[position[0]+1][position[1]].getMob().getNaam()+ ".");
}
}
}
}
}
}
//and some getters etc
}
The problem lies whenever I try to access dungeon in the DungeonRoom object the player is in.
The DungeonMap is made through a .txt file looking something like this:
fffffffffff
spp0p1fffff
fffffffffff
with f being forest, s being starter point, p being path, and numbers the IDs of the enemies standing there