added getPiece method to return piece into ishiglighted, doesnt work ATM
but i think its because getpiece returns null when starting the game, the ishiglighted method might not like it
This commit is contained in:
parent
7ab2b45919
commit
8a67fc5aff
|
|
@ -121,8 +121,7 @@ public class Board {
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void userTouch(int x, int y) {
|
public void userTouch(int x, int y) {
|
||||||
|
|
||||||
if(selectX == -1 && selectY == -1) { // if initial position for select x and y
|
if(selectX == -1 && selectY == -1) { // if initial position for select x and y
|
||||||
if(setSelectXY(x,y) == true) { // checks for pieces at the position x and y
|
if(setSelectXY(x,y) == true) { // checks for pieces at the position x and y
|
||||||
selectX = x; //set select x to x
|
selectX = x; //set select x to x
|
||||||
|
|
@ -146,9 +145,11 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setSelectXY(int x, int y) { //verify if there is a piece at the coordinates of the point selectX;selectY
|
public boolean setSelectXY(int x, int y) { //verify if there is a piece at the coordinates of the point selectX;selectY
|
||||||
boolean isPieceHere = false; // setting bool var
|
boolean isPieceHere = false; // setting bool var
|
||||||
|
|
||||||
for (Piece piece : pieces) { // iterate trough all pieces
|
for (Piece piece : pieces) { // iterate trough all pieces
|
||||||
|
|
||||||
if (piece.getX() == x && piece.getY() == y) {
|
if (piece.getX() == x && piece.getY() == y) {
|
||||||
isPieceHere = !isPieceHere; //chnaging the value to true if a piece is at the coordinates
|
isPieceHere = !isPieceHere; //chnaging the value to true if a piece is at the coordinates
|
||||||
}
|
}
|
||||||
|
|
@ -182,18 +183,31 @@ public class Board {
|
||||||
|
|
||||||
/* The following methods require more work ! */
|
/* The following methods require more work ! */
|
||||||
|
|
||||||
public boolean isHighlighted(int x, int y) {
|
public boolean isHighlighted(int x, int y) {
|
||||||
boolean isAPieceHere = false ; // final return boolean value
|
boolean isAPieceHere = false ; // final return boolean value
|
||||||
PieceType type = null; // type of piece variable that we will get trough a loop, this will determine the pattern of colors
|
PieceType type = getPiece(x,y).getType(); // type of piece variable that we will get trough a loop, this will determine the pattern of highlights on the board
|
||||||
boolean color = true; // color of the piece for pawns that can only go in -y for black and +Y for white
|
boolean color = getPiece(x,y).isWhite(); //color of the piece for pawns that can only go in -y for black and +Y for white
|
||||||
|
|
||||||
for(int i = 1; i < 2;i++)
|
for(int i = 1; i < 2;i++)
|
||||||
if(selectX == x && selectY == y+i) {
|
|
||||||
|
if(selectX == x && selectY == y+i) {
|
||||||
isAPieceHere = true;
|
isAPieceHere = true;
|
||||||
}
|
}
|
||||||
return isAPieceHere;
|
return isAPieceHere;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Piece getPiece(int x, int y) {
|
||||||
|
Piece concernedPiece = null; //initialization of piece var
|
||||||
|
for (Piece piece : pieces) { //iterating through all pieces
|
||||||
|
|
||||||
|
if (piece.getX() == x && piece.getY() == y) { // match with coordinates
|
||||||
|
|
||||||
|
concernedPiece = piece;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return concernedPiece; // returns the piece
|
||||||
|
}
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
//TODO
|
//TODO
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,10 @@ public class Piece {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//in prevision to change the type of a pawn that could get to the other side of the board
|
||||||
|
public void setType (PieceType type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
//idea to add indexes to each pieces
|
//idea to add indexes to each pieces
|
||||||
//public int getIndex() {
|
//public int getIndex() {
|
||||||
// return index;
|
// return index;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue