Ejemplo n.º 1
0
 /**
  * Realise le roque (deplace les pieces)
  *
  * @param myCoup (le coup joue)
  */
 public void realiserRoque(Coup myCoup) {
   Piece roi = null;
   Piece tour = null;
   if (myCoup.estPetitRoque) {
     if (myCoup.getCouleur().getColor() == 1) // blanc
     {
       roi = this.getPiecePosition(4, 0);
       tour = this.getPiecePosition(7, 0);
       roi.setPos(6, 0);
       tour.setPos(5, 0);
     } else {
       roi = this.getPiecePosition(4, 7);
       tour = this.getPiecePosition(7, 7);
       roi.setPos(6, 7);
       tour.setPos(5, 7);
     }
   } else {
     if (myCoup.getCouleur().getColor() == 1) // blanc
     {
       roi = this.getPiecePosition(4, 0);
       tour = this.getPiecePosition(0, 0);
       roi.setPos(2, 0);
       tour.setPos(3, 0);
     } else {
       roi = this.getPiecePosition(4, 7);
       tour = this.getPiecePosition(0, 7);
       roi.setPos(2, 7);
       tour.setPos(3, 7);
     }
   }
 }
Ejemplo 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;
  }
Ejemplo n.º 3
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);
 }