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);
 }
Example #3
0
 /**
  * @param posDepart
  * @param posArrivee
  * @param isPrise
  */
 public void annulerDeplacerPiecePourTest(
     Position posDepart, Position posArrivee, boolean isPrise) {
   Piece pieceD = null;
   pieceD = this.getPiecePosition(posArrivee);
   pieceList.remove(pieceD);
   pieceD.setPos(posDepart);
   if (isPrise) {
     piecePourTest.setPos(posArrivee);
     pieceList.add(piecePourTest);
   }
   piecePourTest = null;
   pieceList.add(pieceD);
 }
Example #4
0
 /**
  * Deplace une piece sans faire de test
  *
  * @param posDepart
  * @param posArrivee
  * @return s'il y a une prise de piece
  */
 public boolean deplacerPiecePourTest(Position posDepart, Position posArrivee) {
   Piece pieceD = null;
   boolean prise = false;
   pieceD = this.getPiecePosition(posDepart);
   piecePourTest = this.getPiecePosition(posArrivee);
   if (piecePourTest != null) {
     prise = true;
     pieceList.remove(piecePourTest);
   }
   pieceD.setPos(posArrivee);
   pieceList.remove(pieceD);
   pieceList.add(pieceD);
   return prise;
 }
Example #5
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;
 }
Example #6
0
 /**
  * @param queen
  * @return add une dame a la LinkedList de piece
  */
 public boolean addQueen(Dame queen) {
   return pieceList.add(queen);
 }
Example #7
0
 /**
  * @param knight
  * @return add un cavalier a la LinkedList de piece
  */
 public boolean addKnight(Cavalier knight) {
   return pieceList.add(knight);
 }
Example #8
0
 /**
  * @param king
  * @return add un roi a la LinkedList de piece
  */
 public boolean addKing(Roi king) {
   return pieceList.add(king);
 }
Example #9
0
 /**
  * @param bishop
  * @return add un fou a la LinkedList de piece
  */
 public boolean addBishop(Fou bishop) {
   return pieceList.add(bishop);
 }
Example #10
0
 /**
  * @param rook
  * @return add une tour a la LinkedList de piece
  */
 public boolean addRook(Tour rook) {
   return pieceList.add(rook);
 }
Example #11
0
 /**
  * @param pawn
  * @return add un pion a la LinkedList de piece
  */
 public boolean addPawn(Pion pawn) {
   return pieceList.add(pawn);
 }
Example #12
0
 /** @return pieceList.size() */
 public int size() {
   return pieceList.size();
 }