From b79b4b81316e71f76da50049fd35f7ac1eedd949 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 29 Dec 2023 02:19:06 +0100 Subject: [PATCH] =?UTF-8?q?des=20id=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Plateau.hpp | 4 ++-- src/Butin/Butin.cpp | 19 +++++++++++++++---- src/Plateau.cpp | 12 +++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/includes/Plateau.hpp b/includes/Plateau.hpp index 6b57d54..aa0613e 100644 --- a/includes/Plateau.hpp +++ b/includes/Plateau.hpp @@ -31,8 +31,8 @@ public: // Si piece = nullptr alors on retire la pièce du plateau void modifierPlateau(const int x, const int y, Piece *piece) const; - // Fonction pour bouger une pièce - void moveSelection(const int x, const int y); + // Fonction pour bouger une pièce, renvoie les anciennes coordonnées + std::pair moveSelection(const int x, const int y); // Renvoie une pièce à une position donnnée Piece *getPiece(const int x, const int y) const; diff --git a/src/Butin/Butin.cpp b/src/Butin/Butin.cpp index 81af5df..1140296 100644 --- a/src/Butin/Butin.cpp +++ b/src/Butin/Butin.cpp @@ -106,21 +106,32 @@ void Butin::event(const int x, const int y) { break; } case EnJeu: { + if (!true) { + // TODO: Si plus aucun coup n'est possible + etape = Fini; + Ecran::printMessage("Bravo !"); + } + // TODO Piece *p = getPiece(posCurseur.first, posCurseur.second); plateau.modifierSelection(posCurseur.first, posCurseur.second); if (p == nullptr) { - // TODO - Si le coup est faisable + // TODO - Si le coup est faisable (définir dans PlateauButin ?) if (true) { - plateau.moveSelection(posCurseur.first, posCurseur.second); + std::pair from = + plateau.moveSelection(posCurseur.first, posCurseur.second); + + // Coordonnées de départ : (from.first , from.second) + // Coordonnées d'arrivée : (posCurseur.first, posCurseur.second) + // TODO: Récupérer la/les pièce/s entre ces 2 coordonnées (définir dans + // PlateauButin ?) + // et ajouter les points aux joueurs } } break; } case Fini: { - // TODO: Afficher le nom du gagnant - Ecran::printMessage("Bravo !"); break; } } diff --git a/src/Plateau.cpp b/src/Plateau.cpp index 1363ba3..87fa0c5 100644 --- a/src/Plateau.cpp +++ b/src/Plateau.cpp @@ -138,14 +138,18 @@ void Plateau::modifierSelection(const int x, const int y) { } } -void Plateau::moveSelection(const int x, const int y) { +std::pair Plateau::moveSelection(const int x, const int y) { if (selection == nullptr) { // Ne fais rien si on a rien a bouger - return; + return std::make_pair(-1, -1); } + // Récupère les coordonnées + std::pair ancienneCoordonnees = + std::make_pair(selection->x, selection->y); + // Retire la pièce de là où elle est pour le plateau - plateau[selection->x][selection->y] = nullptr; + plateau[ancienneCoordonnees.first][ancienneCoordonnees.second] = nullptr; // Déplace la pièce sur le plateau modifierPlateau(x, y, selection); @@ -155,4 +159,6 @@ void Plateau::moveSelection(const int x, const int y) { // Déselectionne la pièce modifierSelection(x, y); + + return ancienneCoordonnees; }