diff --git a/src/backend/Board.java b/src/backend/Board.java index e714058..f257810 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -6,6 +6,8 @@ public class Board { private int colNum; private int lineNum; private ArrayList pieces = new ArrayList<>(); + private int x = -1; + private int y = -1; public Board(int colNum, int lineNum) { this.colNum = colNum; @@ -90,14 +92,46 @@ public class Board { return pieces; } - public void userTouch(int x, int y) { - //TODO + public void userTouch(int x, int y) { //NOT WORKING + int sizePieces = pieces.size(); + boolean positionOccupied = false; + for(int j = 1;j <= sizePieces; j++) { + if ((x == pieces.get(j).getX()) && (y == pieces.get(j).getY())){ + positionOccupied = true; + } + } + if ((this.x == -1 ) && (positionOccupied == true)){ + this.x = x; + this.y = y; + } + else { + if((this.x == x) && (this.y == y)) { + this.x = -1; + this.y = -1; + } + else { + boolean foundPiece = false; + int k = 1; + while (foundPiece == false ) { + if ((this.x == pieces.get(k).getX()) && (this.y == pieces.get(k).getY())){ + foundPiece = true; + pieces.get(k).setX(x); + pieces.get(k).setY(y); + } + k += 1; + } + + } + } } public boolean isSelected(int x, int y) { - //TODO - return false; + boolean selection = false; + if ((this.x == x) && (this.y == y)){ + selection = true; + } + return selection; } /* saving-loading feature :*/ diff --git a/src/backend/Piece.java b/src/backend/Piece.java index 45993d6..fa970a6 100644 --- a/src/backend/Piece.java +++ b/src/backend/Piece.java @@ -20,6 +20,14 @@ public class Piece { return y; } + public void setX(int x) { + this.x = x; + } + + public void setY(int y) { + this.y = y; + } + public PieceType getType() { return type; }