-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSameTileMatch.java
39 lines (34 loc) · 1.23 KB
/
SameTileMatch.java
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
import java.util.ArrayList;
import java.util.List;
public class SameTileMatch implements Matchable {
// CONSTRUCTOR
public SameTileMatch() {}
// INTERFACE IMPLEMENTATION
public List<Tile> match(List<List<Tile>> gameBoard) {
String toBeMatched = null;
List<Tile> matched = new ArrayList<>();
// for each tile
for (List<Tile> innerList : gameBoard) {
for (Tile tile : innerList) {
// get display of tile
String display = tile.getDisplay();
// check for non-null Tile display and non-"removed" Memory Tile
if (!(display == null) && !(display.equals("X"))) {
// initialize toBeMatched
if (toBeMatched == null) {
toBeMatched = display;
}
// find tile with a display that matches toBeMatched
if (tile.getDisplay().equals(toBeMatched)) {
matched.add(tile);
}
}
}
}
// in the Memory game, matched should always be a length of 2
if (matched.size() > 1) {
return matched;
}
return null;
}
}