Commit 3ae97982 authored by 9611046's avatar 9611046

made Pawn class

parent f2b5d1a6
package pieces;
import game.Square;
import java.util.ArrayList;
public class Pawn extends Piece {
public Pawn(String ID,String imagePath,String color){
setPieceId(ID);
setImage( imagePath);
setPieceColor(color);
}
public ArrayList<Square> move(Square [][] boardSquares, int x, int y){
//The java.util.ArrayList.clear() method removes all of the elements from this list.The list will be empty after this call returns.
possibleSquares.clear();
if(getPieceColor().equals("w")){
if(x==0){
return possibleSquares;
}
if(boardSquares[x-1][y].getPiece()==null) {
possibleSquares.add(boardSquares[x - 1][y]);
if (x == 6) {
if (boardSquares[4][y].getPiece() == null)
possibleSquares.add(boardSquares[4][y]);
}
}
if ((y > 0) && (boardSquares[x - 1][y - 1].getPiece() != null) && (boardSquares[x - 1][y - 1].getPiece().getPieceColor() != this.getPieceColor()))
possibleSquares.add(boardSquares[x - 1][y - 1]);
if ((y < 7) && (boardSquares[x - 1][y + 1].getPiece() != null) && (boardSquares[x - 1][y + 1].getPiece().getPieceColor() != this.getPieceColor()))
possibleSquares.add(boardSquares[x - 1][y + 1]);
}
else if(getPieceColor().equals("b")) {
if (x == 8)
return possibleSquares;
if (boardSquares[x + 1][y].getPiece() == null) {
possibleSquares.add(boardSquares[x + 1][y]);
if (x == 1) {
if (boardSquares[3][y].getPiece() == null)
possibleSquares.add(boardSquares[3][y]);
}
}
if ((y > 0) && (boardSquares[x + 1][y - 1].getPiece() != null) && (boardSquares[x + 1][y - 1].getPiece().getPieceColor() != this.getPieceColor()))
possibleSquares.add(boardSquares[x + 1][y - 1]);
if ((y < 7) && (boardSquares[x + 1][y + 1].getPiece() != null) && (boardSquares[x + 1][y + 1].getPiece().getPieceColor() != this.getPieceColor()))
possibleSquares.add(boardSquares[x + 1][y + 1]);
}
return possibleSquares;
}
}
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