Example #1
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;
  }
Example #2
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;
 }