/** * method that will be called when mouse releases * @param point , the point mouse release at */ public void onMouseRelease(Location point) { isGrabbed = false; if(!success){ for(Piece p: bp){ //if correctly matched if(p.contains(grabbedPiece.getCenter()) && p.equals(grabbedPiece)){ grabbedPiece.hide(); p.show(); p.showHighlight(Color.GREEN); lockedBP[p.getId()] = true; //check if all pieces are matched boolean check = true; for(boolean b: lockedBP){ check = check && b; } if(check){ success = true; for(Piece piece: bp){ piece.hideHighlight(); } text.show(); } } } } }
/** * method that will be called when mouse presses * @param point , the point mouse press at */ public void onMousePress(Location point){ if(!success){ for(Piece p: pp){ if(p.contains(point)){ grabbedPiece = p; isGrabbed = true; lastPoint = point; break; } } } else{ for(Piece p: bp){ if(((BoardPiece)p).getImage().contains(point)){ isGrabbed = true; lastPoint = point; break; } } } }