summaryrefslogtreecommitdiffstats
path: root/src/Tile.java
blob: f2548f7d22e79a90ad4dd8db407a44f03a8d2d25 (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
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;
	}
}