diff --git a/cicaprojekt/Dungeon.java b/cicaprojekt/Dungeon.java index dd890e7..2bc7815 100644 --- a/cicaprojekt/Dungeon.java +++ b/cicaprojekt/Dungeon.java @@ -1,9 +1,35 @@ package cicaprojekt; import java.io.*; +import java.util.HashMap; +import java.util.Map; public class Dungeon { - cicaprojekt.Tile buildDungeon(File input) throws IOException + /* NOTE: this function assumes that the parameter input is a well-formatted dungeon file. + * Such file looks like as follows: + * + * x + * + * + * ... + * ... + * > + * + * ---- + * ... + * ... + * ---- + * + * where the map matrix is a matrix of the following chars: + * W: Wall + * F: Field + * Z: Field with a ZMP + * B: Field with a Box + * O: Field with ONeill + * J: Field with Jaffa + * G: Gate + * S: Scale */ + Map buildDungeon(File input) throws IOException { Tile oneilllocation = null; Tile jaffalocation = null; @@ -17,8 +43,9 @@ public class Dungeon { Tile[][] dungeon = new Tile[width][height]; String line = null; - Gate gate = new Gate(); - Gate lastgate = gate; + Gate tempgate = new Gate(); + Scale tempscale = new Scale(tempgate, Integer.MAX_VALUE); + int scalecount = 0; for (int y = 0; y < height; ++y) { line = reader.readLine().replaceAll("\\s",""); // read line and remove whitespaces @@ -59,19 +86,27 @@ public class Dungeon { break; case 'G': - dungeon[y][x] = gate; - lastgate = gate; - gate = new Gate(); + dungeon[y][x] = tempgate; break; case 'S': - dungeon[y][x] = new Scale(lastgate, 5); + dungeon[y][x] = tempscale; + scalecount++; break; } } } - // NOTE: code seems to be correct till this point based on a debugger run-through + reader.readLine(); // throw empty line away + + for (int i = 0; i < scalecount; ++i) // set up scale-gate connections + { + String[] scaledata = reader.readLine().split("-"); + + dungeon[Integer.parseInt(scaledata[0])][Integer.parseInt(scaledata[1])] = + new Scale((Gate)dungeon[Integer.parseInt(scaledata[2])][Integer.parseInt(scaledata[3])], + Integer.parseInt(scaledata[4])); + } /* setting up Tile cross references */ for (int y = 0; y < height; ++y) @@ -100,6 +135,11 @@ public class Dungeon { } } } - return oneilllocation; + + Map playermap = new HashMap<>(); + playermap.put("oneill", oneilllocation); + playermap.put("jaffa", jaffalocation); + + return playermap; } } diff --git a/exampledungeon.dungeon b/exampledungeon.dungeon index 81e7b90..6c33bed 100644 --- a/exampledungeon.dungeon +++ b/exampledungeon.dungeon @@ -5,3 +5,5 @@ W O B S W W W G W W W F Z F W W W W W W + +1-3-2-2-5