diff --git a/java/Map.java b/java/Map.java new file mode 100644 index 0000000..373bf1e --- /dev/null +++ b/java/Map.java @@ -0,0 +1,47 @@ +public class Map { + private Tile[][] tiles; + + public Map(int width, int height, int wWidth, int wHeight, Tile empty, Tile wall) { + int fullHeight = height + (2 * wHeight); + int fullWidth = width + (2 * wWidth); + Tile[][] map = new Tile[fullHeight][fullWidth]; + for (int i = 0; i < fullHeight; i++) { + for (int j = 0; j < fullWidth; j++) { + if (i < wHeight || i >= height + wHeight || j < wWidth || j >= width + wWidth) { + map[i][j] = wall; + } else { + map[i][j] = empty; + } + } + } + this.tiles = map; + } + + public Tile[][] getTiles() { + return this.tiles; + } + + public void generateStructure(String name, int x, int y) { + for (Structure structure : Structure.getStructures()) { + if (name.equals(structure.getName())) { + this.placeStructure(structure, x, y); + } + } + } + + private void placeStructure(Structure structure, int x, int y) { + + } + + public String toString() { + Tile[][] tiles = this.getTiles(); + String str = ""; + for (int i = 0; i < tiles.length; i++) { + for (int j = 0; j < tiles[i].length; j++) { + str += tiles[i][j].toChar(); + } + str += "\n"; + } + return str; + } +} \ No newline at end of file diff --git a/java/Structure.java b/java/Structure.java new file mode 100644 index 0000000..9f11e9b --- /dev/null +++ b/java/Structure.java @@ -0,0 +1,39 @@ +import java.util.ArrayList; + +public class Structure { + private static ArrayList structures; + private Tile[][] tiles; + private String name; + + public Structure(String name, Tile[][] tiles) { + this.name = name; + this.tiles = tiles; + structures.add(this); + } + + public String getName() { + return this.name; + } + + public Tile[][] getTiles() { + return this.tiles; + } + + public static ArrayList getStructures() { + return structures; + } + + public int getWidth() { + return this.tiles.length; + } + + public int getHeight() { + int max = 0; + for (Tile[] tile : this.tiles) { + if (tile.length > max) { + max = tile.length; + } + } + return max; + } +} \ No newline at end of file diff --git a/java/Test.java b/java/Test.java new file mode 100644 index 0000000..b92d3d8 --- /dev/null +++ b/java/Test.java @@ -0,0 +1,8 @@ +public class Test { + public static void main(String[] args) { + Tile wall = new Tile('#', true, "NONE"); + Tile empty = new Tile('+', false, "NONE"); + Map map = new Map(50, 5, 5, 5, empty, wall); + System.out.println(map); + } +} \ No newline at end of file diff --git a/java/Tile.java b/java/Tile.java index 1a3f65e..8d6038c 100644 --- a/java/Tile.java +++ b/java/Tile.java @@ -5,7 +5,7 @@ public class Tile { private Action action; private int[] teleportTarget; - public Tile (char representation, boolean solid, String action) { + public Tile (char representation, boolean solid, String action) throws IllegalArgumentException { this.representation = representation; this.solid = solid; this.action = Action.valueOf(action.toUpperCase()); @@ -16,12 +16,16 @@ public class Tile { } } - public Tile (char representation, boolean solid, String action, int x, int y) { + public Tile (char representation, boolean solid, String action, int x, int y) throws IllegalArgumentException { this.representation = representation; this.solid = solid; this.action = Action.valueOf(action.toUpperCase()); - int[] intArray = {x, y}; - this.teleportTarget = intArray; + if (this.action == Action.TELEPORT) { + int[] intArray = {x, y}; + this.teleportTarget = intArray; + } else { + throw new IllegalArgumentException("A non-teleport tile can't have a teleport target."); + } } public char toChar() {