diff --git a/src/ChessBoardGUI.java b/src/ChessBoardGUI.java index c7cd2cb738fa62ae90f7bdba0e2655326f3f9dbf..4d6ce70d8b3c55b1a09f551d2abf4a31aa32fcfb 100644 --- a/src/ChessBoardGUI.java +++ b/src/ChessBoardGUI.java @@ -21,7 +21,8 @@ public class ChessBoardGUI extends JPanel { public ChessBoardGUI(JPanel removedPiecePanel){ super(); - this.removedPiecePanel=removedPiecePanel; + + this.removedPiecePanel=removedPiecePanel; // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(800,600); diff --git a/src/Pawn.java b/src/Pawn.java index b859fbae652a1544e196c204a2e57db7526bdf38..45c8c8690d5fe66d0aa52b8ad4ef30a4ff279b1d 100644 --- a/src/Pawn.java +++ b/src/Pawn.java @@ -1,8 +1,8 @@ public class Pawn extends Piece{ private boolean once, end ; - public Pawn(Cell cell, PieceColor pieceColor) { - super(cell, pieceColor) ; + public Pawn(Cell cell, PieceColor color) { + super(cell, color) ; this.once = true ; this.end = false ; } @@ -18,18 +18,22 @@ public class Pawn extends Piece{ @Override public boolean isValidMove(Cell c, Cell board[][], Piece pw[], Piece pb[]) { if (super.isDeleted()) return false ; - if (super.getPieceColor()== PieceColor.BLACK && super.getCell().getRow()==0) end = true ; - if (super.getPieceColor()== PieceColor.WHITE && super.getCell().getRow()==7) end = true ; + if (super.getPieceColor()==PieceColor.BLACK && super.getCell().getRow()==0) end = true ; + if (super.getPieceColor()==PieceColor.WHITE && super.getCell().getRow()==7) end = true ; int sw=0 ; if (super.getPieceColor() == PieceColor.BLACK) { for (Piece p:pw) { - if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()) sw=1 ; + if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol() + && c.getRow()-this.getCell().getRow()==-1 + && Math.abs(this.getCell().getCol()-c.getCol())==1) sw=1 ; } } else { for (Piece p:pb) { - if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol()) sw=1 ; + if (!p.isDeleted() && p.getCell().getRow()==c.getRow() && p.getCell().getCol()==c.getCol() + && c.getRow()-this.getCell().getRow()==1 + && Math.abs(this.getCell().getCol()-c.getCol())==1) sw=1 ; } } @@ -55,13 +59,13 @@ public class Pawn extends Piece{ } else { if( - (this.getCell().getCol() == c.getCol() && - ((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()== PieceColor.BLACK) || - (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()== PieceColor.WHITE)) ) + (this.getCell().getCol() == c.getCol() && c.isEmpty() && + ((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()==PieceColor.BLACK) || + (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()==PieceColor.WHITE)) ) || (Math.abs(this.getCell().getCol()-c.getCol())==Math.abs(this.getCell().getRow()-c.getRow()) && - ((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()== PieceColor.BLACK && sw==1) || - (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()== PieceColor.WHITE && sw==1)) ) + ((this.getCell().getRow()-c.getRow()==1 && super.getPieceColor()==PieceColor.BLACK && sw==1) || + (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()==PieceColor.WHITE && sw==1)) ) ) return true ; else return false ; }