diff --git a/includes/Dames/Dames.hpp b/includes/Dames/Dames.hpp index a9ca4a2..242686d 100644 --- a/includes/Dames/Dames.hpp +++ b/includes/Dames/Dames.hpp @@ -25,7 +25,7 @@ class Dames : private Jeu { // Permet de transformer une Piece en PieceDames const PieceDames *getPiece(const int x, const int y) const; - PieceDames *getPiece(Piece *) const; + const PieceDames *getPiece(Piece *) const; // Message à chaque tour du joueur const std::string msgTonTour() const; diff --git a/src/Dames/Dames.cpp b/src/Dames/Dames.cpp index bb57876..feb5b7c 100644 --- a/src/Dames/Dames.cpp +++ b/src/Dames/Dames.cpp @@ -30,8 +30,8 @@ const PieceDames *Dames::getPiece(const int x, const int y) const { return dynamic_cast(plateau.getPiece(x, y)); } -PieceDames *Dames::getPiece(Piece *piece) const { - return dynamic_cast(piece); +const PieceDames *Dames::getPiece(Piece *piece) const { + return dynamic_cast(piece); } const std::string Dames::msgTonTour() const { @@ -122,71 +122,63 @@ bool Dames::prisePossible(Joueur &joueur) const { const std::vector &pieces = joueur.getPieces(); const PieceDames *pieceAPrendre; for (uint i = 0; i < pieces.size(); i++) { - const PieceDames *p = dynamic_cast(pieces[i]); + const PieceDames *p = getPiece(pieces[i]); const Position pos = p->getPos(); if (!p) { throw std::runtime_error("Cette pièce est.. étrange."); } // On regarde si une prise est possible pour chaque coté de la piece if (pos.first > 1) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first - 1, pos.second)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.first > 1 && pos.second > 1) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first - 1, pos.second - 1)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second - 1)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.first > 1 && pos.second < 8) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first - 1, pos.second + 1)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second + 1)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.second > 1) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first, pos.second - 1)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first, pos.second - 1)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.second < 8) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first, pos.second + 1)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first, pos.second + 1)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.first < 8 && pos.second > 1) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first + 1, pos.second - 1)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second - 1)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.first < 8 && pos.second < 8) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first + 1, pos.second + 1)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second + 1)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true; } } if (pos.first < 8) { - pieceAPrendre = dynamic_cast( - plateau.getPiece(pos.first + 1, pos.second)); + pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second)); if (pieceAPrendre != nullptr && pieceAPrendre->getCategory() != p->getCategory()) { return true;