From 98b75c48be66d306985ad5d093944e72be89bbd4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 7 Jan 2024 12:56:41 +0100 Subject: [PATCH] emptyPos --- includes/types.hpp | 3 +++ src/Butin/Butin.cpp | 2 +- src/Dames/Dames.cpp | 2 +- src/Plateau.cpp | 2 +- src/Safari/PlateauSafari.cpp | 4 +++- src/Safari/Safari.cpp | 2 +- src/types.cpp | 5 +++++ 7 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 src/types.cpp diff --git a/includes/types.hpp b/includes/types.hpp index 5777b1b..004d7f1 100644 --- a/includes/types.hpp +++ b/includes/types.hpp @@ -4,3 +4,6 @@ using Position = std::pair; using PositionMutable = std::pair; + +// Renvoie une position invalide +Position emptyPosition(); diff --git a/src/Butin/Butin.cpp b/src/Butin/Butin.cpp index 2286b8a..946f185 100644 --- a/src/Butin/Butin.cpp +++ b/src/Butin/Butin.cpp @@ -161,7 +161,7 @@ void Butin::event(const int x, const int y) { const Position Butin::getPosition() const { if (posCurseur.second > plateau.getTaille() - 1) { std::cerr << "Position inconnu du plateau.\n"; - return std::make_pair(-1, -1); + return emptyPosition(); } return posCurseur; diff --git a/src/Dames/Dames.cpp b/src/Dames/Dames.cpp index c040eb6..d4a4ffd 100644 --- a/src/Dames/Dames.cpp +++ b/src/Dames/Dames.cpp @@ -33,7 +33,7 @@ void Dames::event(const int, const int) {} const Position Dames::getPosition() const { if (posCurseur.second > plateau.getTaille() - 1) { std::cerr << "Position inconnu du plateau.\n"; - return std::make_pair(-1, -1); + return emptyPosition(); } return posCurseur; diff --git a/src/Plateau.cpp b/src/Plateau.cpp index 9daf0a2..8d1165b 100644 --- a/src/Plateau.cpp +++ b/src/Plateau.cpp @@ -145,7 +145,7 @@ void Plateau::modifierSelection(const int x, const int y) { const Position Plateau::moveSelection(const int x, const int y) { if (selection == nullptr) { // Ne fais rien si on a rien a bouger - return std::make_pair(-1, -1); + return emptyPosition(); } // Récupère les coordonnées diff --git a/src/Safari/PlateauSafari.cpp b/src/Safari/PlateauSafari.cpp index 5986900..cca3a8c 100644 --- a/src/Safari/PlateauSafari.cpp +++ b/src/Safari/PlateauSafari.cpp @@ -1,7 +1,9 @@ #include "../../includes/Safari/PlateauSafari.hpp" #include "../../includes/Ecran.hpp" -PlateauSafari::PlateauSafari() : Plateau(8) { +PlateauSafari::PlateauSafari() + : Plateau(8), placementBarriere1(emptyPosition()), + placementBarriere2(emptyPosition()) { // Au début, le plateau est vide // Les joueurs vont choisir leur animal, on place autant d'animal différent diff --git a/src/Safari/Safari.cpp b/src/Safari/Safari.cpp index cf9012a..f39676a 100644 --- a/src/Safari/Safari.cpp +++ b/src/Safari/Safari.cpp @@ -240,7 +240,7 @@ void Safari::event(const int x, const int y) { const Position Safari::getPosition() const { if (posCurseur.second > plateau.getTaille() - 1) { std::cerr << "Position inconnu du plateau.\n"; - return std::make_pair(-1, -1); + return emptyPosition(); } return posCurseur; diff --git a/src/types.cpp b/src/types.cpp new file mode 100644 index 0000000..0aa1a78 --- /dev/null +++ b/src/types.cpp @@ -0,0 +1,5 @@ +#include "../includes/types.hpp" + +Position emptyPosition() { + return std::make_pair(-1, -1); +}