Commit 6f8bb035 authored by kimia's avatar kimia

pawn move

parent a771ed9e
...@@ -21,7 +21,8 @@ public class ChessBoardGUI extends JPanel { ...@@ -21,7 +21,8 @@ public class ChessBoardGUI extends JPanel {
public ChessBoardGUI(JPanel removedPiecePanel){ public ChessBoardGUI(JPanel removedPiecePanel){
super(); super();
this.removedPiecePanel=removedPiecePanel;
this.removedPiecePanel=removedPiecePanel;
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800,600); setSize(800,600);
......
public class Pawn extends Piece{ public class Pawn extends Piece{
private boolean once, end ; private boolean once, end ;
public Pawn(Cell cell, PieceColor pieceColor) { public Pawn(Cell cell, PieceColor color) {
super(cell, pieceColor) ; super(cell, color) ;
this.once = true ; this.once = true ;
this.end = false ; this.end = false ;
} }
...@@ -18,18 +18,22 @@ public class Pawn extends Piece{ ...@@ -18,18 +18,22 @@ public class Pawn extends Piece{
@Override @Override
public boolean isValidMove(Cell c, Cell board[][], Piece pw[], Piece pb[]) { public boolean isValidMove(Cell c, Cell board[][], Piece pw[], Piece pb[]) {
if (super.isDeleted()) return false ; if (super.isDeleted()) return false ;
if (super.getPieceColor()== PieceColor.BLACK && super.getCell().getRow()==0) end = true ; 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.WHITE && super.getCell().getRow()==7) end = true ;
int sw=0 ; int sw=0 ;
if (super.getPieceColor() == PieceColor.BLACK) { if (super.getPieceColor() == PieceColor.BLACK) {
for (Piece p:pw) { 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 { else {
for (Piece p:pb) { 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{ ...@@ -55,13 +59,13 @@ public class Pawn extends Piece{
} }
else { else {
if( if(
(this.getCell().getCol() == c.getCol() && (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.BLACK) ||
(this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()== PieceColor.WHITE)) ) (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()==PieceColor.WHITE)) )
|| ||
(Math.abs(this.getCell().getCol()-c.getCol())==Math.abs(this.getCell().getRow()-c.getRow()) && (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.BLACK && sw==1) ||
(this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()== PieceColor.WHITE && sw==1)) ) (this.getCell().getRow()-c.getRow()==-1 && super.getPieceColor()==PieceColor.WHITE && sw==1)) )
) return true ; ) return true ;
else return false ; 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