From ad09ee4b1d5576415fd60c5cdbc3ebd9de33961a Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 29 Nov 2017 10:50:15 +0100 Subject: [PATCH] Added a proposal of the new Tile object. This is just a proposal of the new Tile object, an may be changed at any time. Allowing it to return an integer on onWalk lets us easier do tasks like looking for wild pokemon, from anywhere in the program. It cannot be used as it is now, but it can be used once we are finished with the other necessary classes. --- java/Tile.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 java/Tile.java diff --git a/java/Tile.java b/java/Tile.java new file mode 100644 index 0000000..1a3f65e --- /dev/null +++ b/java/Tile.java @@ -0,0 +1,53 @@ +public class Tile { + private char representation; + private boolean solid; + private enum Action { TELEPORT, NONE, ENCOUNTER, MENUBATTLE, MENUSHOP } + private Action action; + private int[] teleportTarget; + + public Tile (char representation, boolean solid, String action) { + this.representation = representation; + this.solid = solid; + this.action = Action.valueOf(action.toUpperCase()); + if (this.action != Action.TELEPORT) { + this.teleportTarget = null; + } else { + throw new IllegalArgumentException("A teleport tile must have a valid target."); + } + } + + public Tile (char representation, boolean solid, String action, int x, int y) { + this.representation = representation; + this.solid = solid; + this.action = Action.valueOf(action.toUpperCase()); + int[] intArray = {x, y}; + this.teleportTarget = intArray; + } + + public char toChar() { + return this.representation; + } + + public int[] getTeleportTarget() { + return this.teleportTarget; + } + + public int onWalk() { + if (this.solid) { + System.out.println("You bumped against an immovable structure."); + return -1; + } else { + switch (this.action) { + case TELEPORT: + return 1; + case ENCOUNTER: + return 2; + case MENUBATTLE: + return 3; + case MENUSHOP: + return 4; + } + } + return 0; + } +} \ No newline at end of file