Commit 6f8bb035 authored by kimia's avatar kimia

pawn move

parent a771ed9e
......@@ -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);
......
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 ;
}
......
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