summaryrefslogtreecommitdiffstats
path: root/src/Tile.java
blob: 7420a2acf4a53298baecafcafc3cbb0a749e041e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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<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;
	}

	// 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;
	}
}