check try
This commit is contained in:
parent
72fb02e981
commit
4c7e35a8c8
|
|
@ -6,16 +6,46 @@ import java.lang.Math;
|
|||
|
||||
public class Check {
|
||||
private ArrayList<Piece> altPieces ;
|
||||
private boolean isCheck;
|
||||
private int x;
|
||||
private int y;
|
||||
private int xMove;
|
||||
private int yMove;
|
||||
private Board board;
|
||||
//in Board, add a boolean isChecked ?
|
||||
|
||||
public Check (ArrayList<Piece> pieces) {
|
||||
public Check (ArrayList<Piece> pieces, int x, int y, int xMove, int yMove) {
|
||||
altPieces = pieces;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.xMove = xMove;
|
||||
this.yMove = yMove;
|
||||
}
|
||||
|
||||
public int whatPiece(int x, int y) { // method which gives the index (in the pieces array) of the piece at a position x,y
|
||||
boolean pieceHere = false;
|
||||
int index = 0;
|
||||
while (pieceHere == false && index != altPieces.size()) {
|
||||
if((x == altPieces.get(index).getX()) && (y == altPieces.get(index).getY())){
|
||||
pieceHere =true;
|
||||
}
|
||||
else {
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
if(index == altPieces.size()) {
|
||||
index=-1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public boolean kingCheck() {
|
||||
altPieces.get(whatPiece(this.x,this.y)).setX(this.xMove);
|
||||
return isCheck;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue