-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquareBoard.java
64 lines (53 loc) · 1.83 KB
/
SquareBoard.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
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
package chess.model.game.board;
import chess.model.game.Position;
import java.awt.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class SquareBoard implements BoardModel {
private final int rows;
private final int columns;
private final List<BoardCase> boardCases;
private final Color blackCaseColor;
private final Color whiteCaseColor;
public SquareBoard(int rowsAndCols, Color whiteCaseColor, Color blackCaseColor) {
this.rows = rowsAndCols;
this.columns = rowsAndCols;
this.whiteCaseColor = whiteCaseColor;
this.blackCaseColor = blackCaseColor;
boardCases = createBoardCases();
}
public SquareBoard(int rowsAndCols) {
this.rows = rowsAndCols;
this.columns = rowsAndCols;
this.whiteCaseColor = new Color(238,238,210);
this.blackCaseColor = new Color(118,150,86);
boardCases = createBoardCases();
}
private List<BoardCase> createBoardCases() {
List<BoardCase> boardCases = new ArrayList<>();
for (int row = 1; row <= rows; row++) {
for (int col = 1; col <= columns; col++) {
if((row+col)%2 == 0)
boardCases.add(new BoardCase(whiteCaseColor, new Position(row,col)));
else
boardCases.add(new BoardCase(blackCaseColor, new Position(row,col)));
}
}
return boardCases;
}
public int getRows() {
return rows;
}
public int getColumns() {
return columns;
}
@Override
public boolean positionInBoard(Position position) {
return position.getCol() > 0 && position.getCol() <= columns && position.getRow() > 0 && position.getRow() <= rows;
}
@Override
public List<BoardCase> getCases() {
return boardCases;
}
}