diff options
author | Nao Pross <naopross@thearcway.org> | 2018-11-19 00:02:46 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-11-19 00:02:46 +0100 |
commit | bf6bbd5609cd125d8b3e5a7fbe6f2cd49146af49 (patch) | |
tree | d16adf89b93b44c4a040725b54dbfe5ccf84ef14 /src/Map.java | |
parent | Add gitignore, remove binaries (diff) | |
download | Subconscious-java-bf6bbd5609cd125d8b3e5a7fbe6f2cd49146af49.tar.gz Subconscious-java-bf6bbd5609cd125d8b3e5a7fbe6f2cd49146af49.zip |
Diffstat (limited to 'src/Map.java')
-rw-r--r-- | src/Map.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Map.java b/src/Map.java index 7b178cf..a870604 100644 --- a/src/Map.java +++ b/src/Map.java @@ -3,15 +3,19 @@ import java.util.ArrayList; public class Map { private final Dimension size; + // TODO: is there a particular reason to not use a 2D array? private final Tile grid[]; private ArrayList<Actor> actors = new ArrayList<Actor>(); + // TODO: rename to selectedActor? private int actorIndex = -1; + // TODO: make selectedTile? Tile contains x and y members private int selectedX; private int selectedY; public Map(Dimension size) { this.size = size; + // TODO: replace with Dimension.height and Dimension.width which are integer public members this.grid = new Tile[(int) this.size.getWidth() * (int) this.size.getHeight()]; for (int x = 0; x < this.size.getWidth(); x++) { for (int y = 0; y < this.size.getHeight(); y++) { @@ -20,6 +24,7 @@ public class Map { } } + // pathfinding algorithm public ArrayList<Tile> getPath(Actor actor, int x, int y) { ArrayList<Tile> unsettled = new ArrayList<Tile>(); ArrayList<Tile> settled = new ArrayList<Tile>(); @@ -46,10 +51,12 @@ public class Map { settled.add(i); } } + ArrayList<Tile> out = new ArrayList<Tile>(); Tile workingTile = this.getTile(x, y); double bestDistance = 1000000000; Tile bestTile = workingTile; + while (true) { for (Tile i : workingTile.getAdjacent(this)) { if (i.getDistance() < bestDistance) { @@ -69,6 +76,8 @@ public class Map { } public void update(ArrayList<Actor> actorsList, Tile[] tileGrid) { + // TODO: if this is needed for something, implement copy constructors for Actor and Tile + // and delete this code for (Actor actor : actorsList) { Actor newActor = new Actor(actor.getName(), actor.getHP(), actor.isEnemy(), actor.getAgility()); newActor.place(actor.getX(), actor.getY()); @@ -83,6 +92,7 @@ public class Map { } } + // TODO: refractor to resetActorActions(); public void resetActors() { for (Actor actor : this.actors) { if (!actor.isEnemy()) { @@ -112,6 +122,8 @@ public class Map { return actor; } + // TODO: there is the Map cursor and the Mouse cursor, + // a solution to the naming shall be found public void setCursor(int x, int y) { this.getTile(this.selectedX, this.selectedY).setCursor(false); if (x == -1 && y == -1) { @@ -146,6 +158,7 @@ public class Map { this.actors.add(actor); } + // TODO: remove by introducing selectedTile member public void clearSelected() { for (Tile tile : this.grid) { tile.setSelected(false); |