/** * @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); }
/** * 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); } } }
/** * 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; }
/** * 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; }
/** * 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; }