diff options
author | mafaldo <mafaldo@heavyhammer.home> | 2018-11-18 22:29:05 +0100 |
---|---|---|
committer | mafaldo <mafaldo@heavyhammer.home> | 2018-11-18 22:29:05 +0100 |
commit | e2bcaecea59bdf3a4092efdc4b9624b3f83f6fec (patch) | |
tree | 90e70bb3954173c25e63b65bbc64bd78f8c854be /src/Tile.java | |
download | Subconscious-java-e2bcaecea59bdf3a4092efdc4b9624b3f83f6fec.tar.gz Subconscious-java-e2bcaecea59bdf3a4092efdc4b9624b3f83f6fec.zip |
initial commit
Diffstat (limited to 'src/Tile.java')
-rw-r--r-- | src/Tile.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/Tile.java b/src/Tile.java new file mode 100644 index 0000000..f2548f7 --- /dev/null +++ b/src/Tile.java @@ -0,0 +1,105 @@ +import java.util.ArrayList; + +public class Tile { + public enum Type { + CLEAR, GRASS, WATER, MOUNTAIN, NONE + }; + + private final int x, y; + private Type type; + private boolean selected; + private boolean cursorOnIt; + private double cost; + private double distance; + + public Tile(Type type, int x, int y) { + this.setType(type); + this.x = x; + this.y = y; + } + + public ArrayList<Tile> getAdjacent(Map map) { + ArrayList<Tile> out = new ArrayList<>(); + + if (this.getX() > 0) { + out.add(map.getTile(this.getX()-1, this.getY())); + } + + if (this.getX() < map.getSize()-1) { + out.add(map.getTile(this.getX()+1, this.getY())); + } + + if (this.getY() > 0) { + out.add(map.getTile(this.getX(), this.getY()-1)); + } + + if (this.getY() < map.getSize()-1) { + out.add(map.getTile(this.getX(), this.getY()+1)); + } + + return out; + } + + public boolean cursorOnIt() { + return this.cursorOnIt; + } + + public void setCursor(boolean cursor) { + this.cursorOnIt = cursor; + } + + public double getDistance() { + return this.distance; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public double getCost(Actor actor) { + return this.cost; + } + + public Type getType() { + return this.type; + } + + public void setType(Type type) { + this.type = type; + switch (this.type) { + case CLEAR: + this.cost = 1000000000.0; + break; + case GRASS: + this.cost = 1.0; + break; + case WATER: + this.cost = 3.0; + break; + case MOUNTAIN: + this.cost = 8.0; + break; + } + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public void setSelected(boolean set) { + this.selected = set; + } + + public boolean toggleSelect() { + this.selected = !this.selected; + return this.selected; + } + + public boolean isSelected() { + return this.selected; + } +} |