package model;
import java.util.Set;
import java.util.ArrayList;
import javax.swing.ImageIcon;
public class ChessBoard {
private static ArrayList<ChessPiece> pieces;
private ArrayList<Square> squares;
private static final String[] LOCATIONS = {
"A8","B8","C8","D8","E8","F8","G8","H8",
"A7","B7","C7","D7","E7","F7","G7","H7",
"A6","B6","C6","D6","E6","F6","G6","H6",
"A5","B5","C5","D5","E5","F5","G5","H5",
"A4","B4","C4","D4","E4","F4","G4","H4",
"A3","B3","C3","D3","E3","F3","G3","H3",
"A2","B2","C2","D2","E2","F2","G2","H2",
"A1","B1","C1","D1","E1","F1","G1","H1",
};
public ChessBoard(){
squares = new ArrayList<Square>();
pieces = new ArrayList<ChessPiece>();
addLocations();
setSquareColors();
makeChessPieces();
}
private void addLocations(){
for(int i = 0; i < LOCATIONS.length; i++){
squares.add(new Square(LOCATIONS[i]));
}
}
private void setSquareColors(){
for(Square square: squares){
if(square.toString().matches("A1|C1|E1|G1|B2|D2|F2|"
+ "H2|A3|C3|E3|G3|B4|D4|F4|H4|A5|C5|E5|G5|"
+ "B6|D6|F6|H6|A7|C7|E7|G7|B8|D8|F8|H8")){
square.setColor("BROWN");
}
else if(square.toString().matches("A2|C2|E2|G2|B1|D1|F1|"
+ "H1|A4|C4|E4|G4|B3|D3|F3|H3|A6|C6|E6|G6|"
+ "B5|D5|F5|H5|A8|C8|E8|G8|B7|D7|F7|H7")){
square.setColor("WHITE");
}
}
}
public Square getSquare(int i){
return squares.get(i);
}
public static ChessPiece getPiece(int i){
return pieces.get(i);
}
public String getSquareColor(int i){
return squares.get(i).getColor();
}
public ArrayList<Square> getAllSquares(){
return squares;
}
public static ArrayList<ChessPiece> getAllPieces(){
return pieces;
}
public void setSquareImage(int i, ImageIcon image){
getSquare(i).setImage(image);
}
public static void setPieceImage(int i, ImageIcon image){
getPiece(i).setImage(image);
}
public String toString(){
return squares.toString();
}
private void makeChessPieces(){
String letterpb = "p";
String namepb = "pawn";
String colorpb = "BLACK";
pieces.add(new ChessPiece(namepb, letterpb, colorpb));
String letterrb = "r";
String namerb = "rook";
String colorrb = "BLACK";
pieces.add(new ChessPiece(namerb, letterrb, colorrb));
String letternb = "n";
String namenb = "knight";
String colornb = "BLACK";
pieces.add(new ChessPiece(namenb, letternb, colornb));
String letterbb1 = "b1";
String namebb1 = "bishop1";
String colorbb1 = "BLACK";
pieces.add(new ChessPiece(namebb1, letterbb1, colorbb1));
String letterbb2 = "b2";
String namebb2 = "bishop2";
String colorbb2 = "BLACK";
pieces.add(new ChessPiece(namebb2, letterbb2, colorbb2));
String letterqb = "q";
String nameqb = "queen";
String colorqb = "BLACK";
pieces.add(new ChessPiece(nameqb, letterqb, colorqb));
String letterkb = "k";
String namekb = "king";
String colorkb = "BLACK";
pieces.add(new ChessPiece(namekb, letterkb, colorkb));
}
}