détection fin du jeu
This commit is contained in:
parent
d3a2d69dd4
commit
920d25daae
2 changed files with 33 additions and 8 deletions
|
@ -3,8 +3,8 @@
|
|||
#include "../Plateau.hpp"
|
||||
#include <vector>
|
||||
|
||||
class PlateauButin : public Plateau {
|
||||
public:
|
||||
struct PlateauButin : public Plateau {
|
||||
|
||||
PlateauButin();
|
||||
virtual ~PlateauButin();
|
||||
|
||||
|
@ -19,4 +19,9 @@ public:
|
|||
|
||||
// Vrai si un coup est possible
|
||||
bool coupsPossible() const;
|
||||
|
||||
private:
|
||||
// Renvoie la liste des pièces entre deux position
|
||||
std::vector<Piece *> cheminPieces(const int depX, const int depY,
|
||||
const int destX, const int destY) const;
|
||||
};
|
||||
|
|
|
@ -48,11 +48,13 @@ void PlateauButin::initialiserPlateau() {
|
|||
|
||||
std::vector<Piece *> PlateauButin::cheminPieces(const int destX,
|
||||
const int destY) const {
|
||||
// Position départ
|
||||
std::pair<int, int> posSelection = selection->getPos();
|
||||
const int depX = posSelection.first;
|
||||
const int depY = posSelection.second;
|
||||
return cheminPieces(posSelection.first, posSelection.second, destX, destY);
|
||||
}
|
||||
|
||||
std::vector<Piece *> PlateauButin::cheminPieces(const int depX, const int depY,
|
||||
const int destX,
|
||||
const int destY) const {
|
||||
// Distances
|
||||
const int deltaX = destX - depX;
|
||||
const int deltaY = destY - depY;
|
||||
|
@ -102,7 +104,25 @@ bool PlateauButin::selectionJaune() const {
|
|||
}
|
||||
|
||||
bool PlateauButin::coupsPossible() const {
|
||||
// TODO: Vérifier si en partant des pièces jaunes il n'y aurait pas des coups
|
||||
// possibles
|
||||
return true;
|
||||
for (int i = 0; i < taille; ++i) {
|
||||
for (int j = 0; j < taille; ++j) {
|
||||
const PieceButin *piece = dynamic_cast<const PieceButin *>(plateau[i][j]);
|
||||
if (piece && piece->getPoints() == PieceButin::Jaune) {
|
||||
// Parmis toutes les pièces jaunes
|
||||
for (int i2 = 0; i2 < taille; ++i2) {
|
||||
for (int j2 = 0; j2 < taille; ++j2) {
|
||||
// Regarde par rapport aux cases vides
|
||||
if (plateau[i2][j2] == nullptr) {
|
||||
// Si le déplacement d'une pièce peut donner des points
|
||||
if (!cheminPieces(i, j, i2, j2).empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Reference in a new issue