import java.util.ArrayList; public class Tile { public enum Type { CLEAR, GRASS, WATER, MOUNTAIN, NONE }; // TODO: make public private final int x, y; // TODO: make final private Type type; // TODO: refractor to inRange; private boolean selected; // TODO: it would be better if the MapScene had a member tileUnderCursor private boolean cursorOnIt; // underCursor? // TODO: make final, or make a table to match type to cost private double cost; // TODO: remove and make here a method // double distanceFrom(Tile other); // or a method in Map.java // double distanceBetween(Tile firstTile, Tile secondTile); private double distance; public Tile(Type type, int x, int y) { this.setType(type); this.x = x; this.y = y; } public ArrayList getAdjacent(Map map) { ArrayList 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; } // TODO: remove this feature and make the member final 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; } // TODO: rename to isInRange() and this.selected => inRange public boolean isSelected() { return this.selected; } }