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
 /**
  * Realise la promotion (change la piece)
  *
  * @param myCoup
  */
 public void realiserPromotion(Coup myCoup) {
   Piece pieceD = null;
   Piece pieceApres = null;
   pieceD = myCoup.getPieceDepart();
   if (pieceD instanceof Pion) pieceApres = ((Pion) pieceD).promotion(myCoup.getPromotion());
   pieceList.remove(pieceD);
   pieceList.add(pieceApres);
 }