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