This commit is contained in:
Mylloon 2024-01-11 23:28:08 +01:00
parent 49fe932bae
commit c2e4c8f968
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 12 additions and 20 deletions

View file

@ -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;

View file

@ -30,8 +30,8 @@ const PieceDames *Dames::getPiece(const int x, const int y) const {
return dynamic_cast<const PieceDames *>(plateau.getPiece(x, y));
}
PieceDames *Dames::getPiece(Piece *piece) const {
return dynamic_cast<PieceDames *>(piece);
const PieceDames *Dames::getPiece(Piece *piece) const {
return dynamic_cast<const PieceDames *>(piece);
}
const std::string Dames::msgTonTour() const {
@ -122,71 +122,63 @@ bool Dames::prisePossible(Joueur &joueur) const {
const std::vector<Piece *> &pieces = joueur.getPieces();
const PieceDames *pieceAPrendre;
for (uint i = 0; i < pieces.size(); i++) {
const PieceDames *p = dynamic_cast<const PieceDames *>(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<const PieceDames *>(
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<const PieceDames *>(
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<const PieceDames *>(
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<const PieceDames *>(
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<const PieceDames *>(
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<const PieceDames *>(
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<const PieceDames *>(
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<const PieceDames *>(
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;