-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
44 lines (36 loc) · 1.06 KB
/
Copy pathBlock.java
File metadata and controls
44 lines (36 loc) · 1.06 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
import java.util.ArrayList;
public abstract class Block {
int id;
int x, y;
int length = 2;
Block(int id, int x, int y) {
this.id = id;
this.x = x;
this.y = y;
}
public Board createNeighbour(Board board, int x, int y) {
Board neighbour = new Board(board);
neighbour.move = new int[][]{{this.x, this.y}, {x, y}};
for (Block block : neighbour.blocks.values()) {
if (block.id == id) {
block.x = x;
block.y = y;
}
}
return neighbour;
}
public abstract ArrayList<Board> getNeighbours(Board board);
public abstract boolean covers(int x, int y);
@Override
public abstract Block clone();
@Override
public boolean equals(Object obj) {
if (obj instanceof Block) {
Block other = (Block) obj;
if (getClass() == other.getClass() && id == other.id && x == other.x && y == other.y && length == other.length) {
return true;
}
}
return false;
}
}