Esempio n. 1
0
 /**
  * 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();
         }
       }
     }
   }
 }
Esempio n. 2
0
  /**
   * Realise un déplacement
   *
   * @param myCoup
   * @return
   */
  @SuppressWarnings("null")
  public boolean realiserCoup(Coup myCoup) {

    Piece pieceD = null;
    Position posA = null;
    piecePourTest = null;

    try {
      pieceD = myCoup.getPieceDepart();
      posA = myCoup.getPosArrivee();
      myCoup.setPiecePrise(this.getPiecePosition(posA));
    } catch (NullPointerException e) {
      e.getStackTrace();
    }
    if (myCoup.getRoque() == false) {
      if (pieceList.contains(pieceD)) {
        if (pieceD.positionAccessibleChessboard(this).contains(posA)) {
          pieceList.remove(this.getPiecePosition(posA));
          for (Piece piece : pieceList) {
            if (piece.equals(pieceD)) {
              pieceD.setPlayed();
              pieceD.setPos(posA);
              pieceList.remove(piece);
              pieceList.add(pieceD);
              break;
            }
          }
          return true;
        }
      } else return false;
    } else {
      realiserRoque(myCoup);
    }
    return false;
  }
Esempio n. 3
0
  /**
   * Determines whether the piece at the given square can be moved, i.e. that there is actually a
   * piece there and that its color matches the color to move.
   */
  public boolean isMovablePieceAtSquare(Square startSquare) {
    final Piece pieceToMove = getPieceAt(startSquare);

    // There should be a piece on the starting square
    if (pieceToMove.equals(Piece.NONE)) {
      return false;
    }
    // The color of the piece being moved must be the color
    // of the player to move
    return (pieceToMove.getColor() == getColorToMove());
  }
Esempio n. 4
0
 /**
  * Deplacer la piece un coup,
  *
  * @param pieceDepart
  * @param posArrivee
  * @return
  */
 public boolean realiserCoup(Piece pieceDepart, Position posArrivee) {
   if (pieceList.contains(pieceDepart)) {
     pieceList.remove(this.getPiecePosition(posArrivee));
     for (Piece piece : pieceList) {
       if (piece.equals(pieceDepart)) {
         pieceDepart.setPos(posArrivee);
         pieceList.remove(piece);
         pieceList.add(pieceDepart);
         break;
       }
     }
     pieceDepart.setPlayed();
     return true;
   } else return false;
 }
  /**
   * Do the Move, removing the piece from x1, y1 and setting the piece in x2, y2. If the piece is
   * now on their "King's Row", then promote the piece should be promoted to a King
   */
  public void execute(final Move move) {

    if (isOnBoard(move.getX1(), move.getY1()) && isOnBoard(move.getX2(), move.getY2())) {
      if (isEmptySquare(move.getX2(), move.getY2())) {

        Piece piece = getPiece(move.getY1(), move.getX1());
        if (piece.equals(Piece.WHITE_MAN)) {
          if (move.getY2() == 7) {
            piece = Piece.WHITE_KING;
          }
        } else {
          if (move.getY2() == 0) {
            piece = Piece.RED_KING;
          }
        }

        setPiece(move.getY2(), move.getX2(), piece);

        removePiece(move.getY1(), move.getX1());
      }
    }
  }