-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
70 lines (60 loc) · 1.7 KB
/
Tile.java
File metadata and controls
70 lines (60 loc) · 1.7 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
public class Tile {
int value;
/*
* creates a tile using the given value. False jokers are not included in this game.
*/
public Tile(int value) {
this.value = value;
}
/*
* TODO: should check if the given tile t and this tile have the same value
* return true if they are matching, false otherwise
*
* Gökdeniz Derelioğlu - done.
*/
public boolean matchingTiles(Tile t) {
return (this.value == t.value);
}
/*
* TODO: should compare the order of these two tiles
* return 1 if given tile has smaller in value
* return 0 if they have the same value
* return -1 if the given tile has higher value
*
* Gökdeniz Derelioğlu - done.
*/
public int compareTo(Tile t) {
int output = 2; //terminal value
if (t.value < this.value)
{
output = 1;
}
else if (t.value == this.value)
{
output = 0;
}
else
{
output = -1;
}
return output;
}
/*
* TODO: should determine if this tile and given tile can form a chain together
* this method should check the difference in values of the two tiles
* should return true if the absoulute value of the difference is 1 (they can form a chain)
* otherwise, it should return false (they cannot form a chain)
*
* Gökdeniz Derelioğlu - done.
*/
public boolean canFormChainWith(Tile t) {
int difference = Math.abs(t.value - this.value);
return (difference == 1);
}
public String toString() {
return "" + value;
}
public int getValue() {
return value;
}
}