-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFigure.java
More file actions
99 lines (63 loc) · 2.3 KB
/
Figure.java
File metadata and controls
99 lines (63 loc) · 2.3 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Chess;
import java.util.List;
public abstract class Figure {
private int rowPosition;
private int colPosition;
private FigureColor figureColor;
private PossiblePositions possiblePositions;
public Figure(int rowPosition, int cowPosition, FigureColor figureColor) {
setRowPosition(rowPosition);
setCowPosition(cowPosition);
setFigureColor(figureColor);
this.possiblePositions = new PossiblePositions();
}
public void setRowPosition(int rowPosition) {
this.rowPosition = rowPosition;
}
public void setCowPosition(int colPosition) {
this.colPosition = colPosition;
}
public abstract void move(int rowPosition, int colPosition);
public String draw(int row, String color) {
return "";
}
public int getRowPosition() {
return rowPosition;
}
public int getColPosition() {
return colPosition;
}
protected void addPossiblePosition(Position position) {
this.possiblePositions.addPosition(position);
}
public abstract void possibleMoves(Figure[][] figures);
protected void isMoveValid(Position position) {
if (!this.validateMove(position)) {
throw new IllegalArgumentException("Invalid move!!");
}
}
protected void emptyMoves() {
this.possiblePositions.getPositionList().clear();
}
public void setFigureColor(FigureColor figureColor) {
this.figureColor = figureColor;
}
public FigureColor getColor() {
return this.figureColor;
}
public List<Position> getPossiblePositions() {
return possiblePositions.getPositionList();
}
public boolean validateMove(Position position) {
List<Position> positionList = this.possiblePositions.getPositionList();
for (int i = 0; i < positionList.size(); i++) {
if (positionList.get(i).getRow() == position.getRow() && positionList.get(i).getCol() == position.getCol()) {
return true;
}
}
return false;
}
public void removeAttackedSquares(){
AttackedSquares.removeAttackedSquares(this.possiblePositions.getPositionList(),this.getColor());
}
}