Commit 05d5172b authored by 9611046's avatar 9611046

first view of pieces on board completed

parent 37957f2d
package game;
import pieces.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
public class Main extends JFrame implements MouseListener{
/**
* @author Newsha Shahbodaghkhan
*/
/**
* This is my Main class GUI is performed in Main
*/
private JButton[][] chessBoardSquares = new JButton[8][8];
// private Image[][] chessPieceImages = new Image[2][6];
// private final JLabel message = new JLabel(
// "Chess Champ is ready to play!");
// public static final int QUEEN = 0, KING = 1,
// ROOK = 2, KNIGHT = 3, BISHOP = 4, PAWN = 5;
// public static final int[] STARTING_ROW = {
// ROOK, KNIGHT, BISHOP, KING, QUEEN, BISHOP, KNIGHT, ROOK };
private Main()
public class Main extends JFrame implements MouseListener{
//I want to make only one instance of Mainboard
private static Main Mainboard;
// private JButton[][] chessBoardSquares ;
private Square [][] chessBoardSquares;
private JFrame myFrame;
private static Rook wr01,wr02,br01,br02;
private static Knight wk01,wk02,bk01,bk02;
private static Bishop wb01,wb02,bb01,bb02;
private static Pawn wp[],bp[];
private static Queen wq,bq;
private static King wk,bk;
public static void main(String[] args) {
// Mainboard.setVisible(true);
wr01=new Rook("WR01", "src\\game\\White_Rook.png","w");
wr02=new Rook("WR02", "src\\game\\White_Rook.png","w");
br01=new Rook("BR01", "src\\game\\Black_Rook.png","b");
br02=new Rook("BR02", "src\\game\\Black_Rook.png","b");
wk01=new Knight("WK01", "src\\game\\White_Knight.png","w");
wk02=new Knight("WK02", "src\\game\\White_Knight.png","w");
bk01=new Knight("BK01", "src\\game\\Black_Knight.png","b");
bk02=new Knight("BK02", "src\\game\\Black_Knight.png","b");
wb01=new Bishop("WB01", "src\\game\\White_Bishop.png","w");
wb02=new Bishop("WB02", "src\\game\\White_Bishop.png","w");
bb01=new Bishop("BB01", "src\\game\\Black_Bishop.png","b");
bb02=new Bishop("BB02", "src\\game\\Black_Bishop.png","b");
wq=new Queen("WQ", "src\\game\\White_Queen.png","w");
bq=new Queen("BQ", "src\\game\\Black_Queen.png","b");
wk=new King("WK", "src\\game\\White_King.png","w",7,3);
bk=new King("BK", "src\\game\\Black_King.png","b",0,3);
wp=new Pawn[8];
bp=new Pawn[8];
for(int i=0;i<8;i++)
{
wp[i]=new Pawn("WP0"+(i+1), "src\\game\\White_Pawn.png","w");
bp[i]=new Pawn("BP0"+(i+1), "src\\game\\Black_Pawn.png","b");
}
Mainboard = new Main();
}
JFrame myFrame = new JFrame("Chess");
private Main() {
chessBoardSquares = new Square[8][8];
myFrame = new JFrame("Chess");
myFrame.setLayout(new BorderLayout(100, 100));
JPanel centerpanel = new JPanel();
......@@ -30,6 +71,7 @@ private Main()
westPanel.setBackground(Color.BLACK);
westPanel.setPreferredSize(new Dimension(400, 30));
westPanel.setLayout(new BorderLayout(3, 1));
JPanel northOfWest = new JPanel();
northOfWest.setPreferredSize(new Dimension(400, 100));
northOfWest.setBackground(new Color(51, 0, 0));
......@@ -49,69 +91,152 @@ private Main()
centerpanel.setBackground(Color.black);
JPanel eastPanel = new JPanel();
// eastPanel.setBackground(Color.RED);
centerpanel.setLayout(new GridLayout(8, 8));
myFrame.add(centerpanel, BorderLayout.CENTER);
myFrame.add(westPanel, BorderLayout.WEST);
myFrame.add(eastPanel, BorderLayout.EAST);
// JPanel[] myJP = new JPanel[64];
// ArrayList<JPanel> myJP=new ArrayList<>(64);
ArrayList<JButton> myJP = new ArrayList<>(64);
for (int i = 0; i < 64; i++) {
JButton j = new JButton();
// JButton[] buttons = new JButton[8];
// for(int k=0;k<8;k++){
// buttons[i]=
// }i
// JButton button = new JButton();
// j.add(button);
// myJP.add(j);
// j.addActionListener(new test(j));
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
chessBoardSquares[i][j] = new Square(i, j);
}
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (i % 2 == j % 2) {
myJP.get((i * 8) + j).setBackground(new Color(51, 51, 51));
chessBoardSquares[i][j].setBackground(new Color(204, 204, 204));
}
if (i % 2 != j % 2) {
myJP.get((i * 8) + j).setBackground(new Color(204, 204, 204));
chessBoardSquares[i][j].setBackground(new Color(51, 51, 51));
}
}
}
// Piece piece;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
// piece = null;
if (i == 0 && j == 0) {
// piece = br01;
chessBoardSquares[i][j].setPiece(br01);
}
else if (i == 0 && j == 7) {
// piece = br02;
chessBoardSquares[i][j].setPiece(br02);
}
else if (i == 7 && j == 0) {
//piece = wr01;
// P.setImage("src\\game\\White_Rook.png");
chessBoardSquares[i][j].setPiece(wr01);
}
else if (i == 7 && j == 7) {
//piece = wr02;
chessBoardSquares[i][j].setPiece(wr02);
}
// myJP.add()
// ArrayList<JButton> button=new ArrayList<>();
// for(int i=0;i<64;i++){button.get(i)=myJP.get(i)}
for (int i = 0; i < 64; i++) {
centerpanel.add(myJP.get(i));
else if (i == 0 && j == 1) {
//piece = bk01;
chessBoardSquares[i][j].setPiece(bk01);
}
else if (i == 0 && j == 6) {
//piece = bk02;
chessBoardSquares[i][j].setPiece(bk02);
}
else if (i == 7 && j == 1) {
//piece = wk01;
chessBoardSquares[i][j].setPiece(wk01);
}
else if (i == 7 && j == 6) {
//piece = wk02;
chessBoardSquares[i][j].setPiece(wk02);
}
else if (i == 0 && j == 2) {
//piece = bb01;
chessBoardSquares[i][j].setPiece(bb01);
}
else if (i == 0 && j == 5) {
//piece = bb02;
chessBoardSquares[i][j].setPiece(bb02);
}
else if (i == 7 && j == 2) {
//piece = wb01;
chessBoardSquares[i][j].setPiece(wb01);
}
else if (i == 7 && j == 5) {
//piece = wb02;
chessBoardSquares[i][j].setPiece(wb02);
}
else if (i == 0 && j == 3) {
//piece = bk;
chessBoardSquares[i][j].setPiece(bk);
}
else if (i == 0 && j == 4) {
//piece = bq;
chessBoardSquares[i][j].setPiece(bq);
}
else if (i == 7 && j == 3) {
//piece = wk;
chessBoardSquares[i][j].setPiece(wk);
}
else if (i == 7 && j == 4) {
//piece = wq;
chessBoardSquares[i][j].setPiece(wq);
}
else if (i == 1) {
// piece = bp[j];
chessBoardSquares[1][j].setPiece(bp[j]);
}
else if (i == 6) {
// piece = wp[j];
chessBoardSquares[6][j].setPiece(wp[j]);
}
// Square square = new Square(i, j, P);
// square.setPiece(P);
// piece= wr02;
// assert P != null;
// piece=new Rook("1","src\\\\game\\\\White_Rook.png","w");
// chessBoardSquares[i][j].setPiece(piece);
}
}
//chessBoardSquares[0][0].selectSquare();
//ImageIcon img = Black_Rook.png;
//JLabel imgLabel = new JLabel(new ImageIcon("Black_Rook.png"));
chessBoardSquares[0][0].add(new JLabel(new ImageIcon("src\\game\\Black_Rook.png")));
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
centerpanel.add(chessBoardSquares[i][j]);
}
}
// JButton b1 = new JButton();
myFrame.setVisible(true);
myFrame.setResizable(true);
myFrame.setExtendedState(myFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
}
@Override
public void mouseClicked(MouseEvent e){
public void mouseClicked (MouseEvent e){
}
@Override
public void mouseEntered(MouseEvent arg0) {
public void mouseEntered (MouseEvent arg0){
}
@Override
public void mouseExited(MouseEvent arg0) {
public void mouseExited (MouseEvent arg0){
}
@Override
public void mousePressed(MouseEvent arg0) {
public void mousePressed (MouseEvent arg0){
}
@Override
public void mouseReleased(MouseEvent arg0) {
public void mouseReleased (MouseEvent arg0){
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment