From 7ee843d29e6159ea0871fc50dd822afbe24f4092 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 12 Jan 2024 01:06:52 +0100 Subject: [PATCH] deplacement Dames OK (au moins le principal je crois...) --- src/Dames/Dames.cpp | 27 +++++++++++---------------- src/Dames/PlateauDames.cpp | 4 +++- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Dames/Dames.cpp b/src/Dames/Dames.cpp index feb5b7c..a0fcd70 100644 --- a/src/Dames/Dames.cpp +++ b/src/Dames/Dames.cpp @@ -75,12 +75,7 @@ void Dames::event(const int x, const int y) { // Test si le déplacement est possible pour un pions : en diagonal en // direction de l'autre joueur // Crash ici parce que p = nullptr donc p->getPos() provoque une segfault - if ((joueurCourant == &joueur1 && - posCurseur.first == p->getPos().first + 1) || - (joueurCourant == &joueur2 && - posCurseur.first == p->getPos().first - 1) && - (posCurseur.second == p->getPos().second + 1 || - posCurseur.second == p->getPos().second - 1)) { + if (p==nullptr) { plateau.moveSelection(posCurseur.first, posCurseur.second); // Donne la main au joueur suivant changerJoueurCourant(); @@ -131,56 +126,56 @@ bool Dames::prisePossible(Joueur &joueur) const { if (pos.first > 1) { pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second)); if (pieceAPrendre != nullptr && - pieceAPrendre->getCategory() != p->getCategory()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first-2, pos.second))==nullptr) { return true; } } if (pos.first > 1 && pos.second > 1) { pieceAPrendre = getPiece(plateau.getPiece(pos.first - 1, pos.second - 1)); if (pieceAPrendre != nullptr && - pieceAPrendre->getCategory() != p->getCategory()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first-2, pos.second-2))==nullptr) { return true; } } if (pos.first > 1 && pos.second < 8) { - pieceAPrendre = getPiece(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()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first-2, pos.second+2))==nullptr) { return true; } } if (pos.second > 1) { pieceAPrendre = getPiece(plateau.getPiece(pos.first, pos.second - 1)); if (pieceAPrendre != nullptr && - pieceAPrendre->getCategory() != p->getCategory()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first, pos.second-2))==nullptr) { return true; } } if (pos.second < 8) { pieceAPrendre = getPiece(plateau.getPiece(pos.first, pos.second + 1)); if (pieceAPrendre != nullptr && - pieceAPrendre->getCategory() != p->getCategory()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first, pos.second+2))==nullptr) { return true; } } if (pos.first < 8 && pos.second > 1) { pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second - 1)); if (pieceAPrendre != nullptr && - pieceAPrendre->getCategory() != p->getCategory()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first+2, pos.second-2))==nullptr) { return true; } } if (pos.first < 8 && pos.second < 8) { - pieceAPrendre = getPiece(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()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first+2, pos.second+2))==nullptr) { return true; } } if (pos.first < 8) { pieceAPrendre = getPiece(plateau.getPiece(pos.first + 1, pos.second)); if (pieceAPrendre != nullptr && - pieceAPrendre->getCategory() != p->getCategory()) { + pieceAPrendre->getCategory() != p->getCategory() && getPiece(plateau.getPiece(pos.first+2, pos.second))==nullptr) { return true; } } diff --git a/src/Dames/PlateauDames.cpp b/src/Dames/PlateauDames.cpp index 1a15c21..8171c12 100644 --- a/src/Dames/PlateauDames.cpp +++ b/src/Dames/PlateauDames.cpp @@ -27,7 +27,9 @@ PlateauDames::~PlateauDames() {} bool PlateauDames::deplacementValideCoor(const int x1, const int y1, const int x2, const int y2) const { - return (x2 == x1 || y2 == y1); + if((x2==x1+1 && y2==y1+1) || (x2==x1-1 && y2==y1-1) || (x2==x1+1 && y2==y1-1) || (x2==x1-1 && y2==y1+1)) + return true; + return false; } // Peut-etre utiliser cette fonction pour prisePossible ?