-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.pde
More file actions
96 lines (79 loc) · 2.1 KB
/
Tile.pde
File metadata and controls
96 lines (79 loc) · 2.1 KB
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
class Tile {
private int value;
private Map<Integer, Integer> colors;
private int positionX;
private int positionY;
private int newPositionX;
private int newPositionY;
public Tile(int value, int positionX, int positionY) {
this.positionX = positionX;
this.positionY = positionY;
this.newPositionX = positionX;
this.newPositionY = positionY;
this.value = value;
generateColors();
}
private void generateColors() {
colors = new HashMap<Integer,Integer>();
colors.put(2,#eee4db);
colors.put(4,#eedfc8);
colors.put(8,#f2b179);
colors.put(16,#ec8d55);
colors.put(32,#f77b5f);
colors.put(64,#ea5a38);
colors.put(128,#f2d04b);
colors.put(256,#f2d04b);
colors.put(512,#f2d04b);
colors.put(1024,#e3ba14);
colors.put(2048,#e3ba14);
}
public int getValue() {
return value;
}
public void growTile() {
value = value*2;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public int getNewPositionX() {
return newPositionX;
}
public int getNewPositionY() {
return newPositionY;
}
public void setPosition(int positionX, int positionY) {
this.positionX = positionX;
this.positionY = positionY;
}
public void setNewPosition(int newPositionX, int newPositionY) {
this.newPositionX = newPositionX;
this.newPositionY = newPositionY;
}
public String toString() {
return value+"";
}
public Tile add(Tile tile) {
tile.setNewPosition(newPositionX,newPositionY);
return new Tile(this.value + tile.value,newPositionX,newPositionY);
}
public color getColor() {
return colors.getOrDefault(this.value,#e3ba14);
}
public int hashCode() {
return Objects.hashCode(value);
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Tile other = (Tile) obj;
return Objects.equals(this.value, other.value);
}
}