diff --git a/includes/Butin/PlateauButin.hpp b/includes/Butin/PlateauButin.hpp index e9d1ac4..352068f 100644 --- a/includes/Butin/PlateauButin.hpp +++ b/includes/Butin/PlateauButin.hpp @@ -1,6 +1,7 @@ #pragma once #include "../Plateau.hpp" +#include class PlateauButin : public Plateau { public: @@ -9,4 +10,7 @@ public: // Initialise le plateau du Butin void initialiserPlateau() override; + + // Renvoie la liste des pièces entre la pièce sélectionné et une position + std::vector cheminPieces(const int destX, const int destY) const; }; diff --git a/src/Butin/PlateauButin.cpp b/src/Butin/PlateauButin.cpp index c233ad3..728aa81 100644 --- a/src/Butin/PlateauButin.cpp +++ b/src/Butin/PlateauButin.cpp @@ -45,3 +45,49 @@ void PlateauButin::initialiserPlateau() { } } } + +std::vector PlateauButin::cheminPieces(const int destX, + const int destY) const { + // Position départ + std::pair posSelection = selection->getPos(); + const int depX = posSelection.first; + const int depY = posSelection.second; + + // Distances + const int deltaX = destX - depX; + const int deltaY = destY - depY; + + // Direction à prendre + const int stepX = (deltaX > 0) ? 1 : -1; + const int stepY = (deltaY > 0) ? 1 : -1; + + std::vector chemin; + + // Déplacement vertical + if (deltaX == 0) { + for (int dy = depY + stepY; dy != destY; dy += stepY) { + chemin.push_back(plateau[depX][dy]); + } + } + + // Déplacement horizontal + else if (deltaY == 0) { + for (int dx = depX + stepX; dx != destX; dx += stepX) { + chemin.push_back(plateau[dx][depY]); + } + } + + // Déplacement en diagonale + else if (abs(deltaX) == abs(deltaY)) { + for (int dx = depX + stepX, dy = depY + stepY; dx != destX; + dx += stepX, dy += stepY) { + chemin.push_back(plateau[dx][dy]); + } + } + + // Retire les cases vides + chemin.erase(std::remove(chemin.begin(), chemin.end(), nullptr), + chemin.end()); + + return chemin; +}