-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHorizontalBlock.java
More file actions
37 lines (32 loc) · 1008 Bytes
/
Copy pathHorizontalBlock.java
File metadata and controls
37 lines (32 loc) · 1008 Bytes
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
import java.util.ArrayList;
public class HorizontalBlock extends Block {
HorizontalBlock(int id, int x, int y) {
super(id, x, y);
}
public ArrayList<Board> getNeighbours(Board board) {
ArrayList<Board> neighbours = new ArrayList<>();
int x = this.x + 1;
while (x + length - 1 < 6 && !board.isSquareOccupied(x + length - 1, y)) {
neighbours.add(createNeighbour(board, x, y));
x++;
}
x = this.x - 1;
while (x >= 0 && !board.isSquareOccupied(x, y)) {
neighbours.add(createNeighbour(board, x, y));
x--;
}
return neighbours;
}
public boolean covers(int x, int y) {
if (y == this.y && x >= this.x && x <= this.x + length - 1) {
return true;
}
return false;
}
@Override
public Block clone() {
HorizontalBlock clone = new HorizontalBlock(id, x, y);
clone.length = this.length;
return clone;
}
}