From 5bfd9dd6a6af1f7c7baf5db2dd1459a3328dba4d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 30 Dec 2023 23:02:45 +0100 Subject: [PATCH] use throw when we can, also throw when 2 screen --- includes/Ecran.hpp | 2 ++ src/Butin/PieceButin.cpp | 3 +-- src/Dames/Dames.cpp | 3 +-- src/Dames/PieceDames.cpp | 3 +-- src/Ecran.cpp | 11 ++++++++++- src/Safari/PieceSafari.cpp | 3 +-- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/includes/Ecran.hpp b/includes/Ecran.hpp index 63acb1d..fd98c64 100644 --- a/includes/Ecran.hpp +++ b/includes/Ecran.hpp @@ -10,6 +10,8 @@ class Ecran { static bool fps; + static int count; + public: // Fenêtre static sf::RenderWindow window; diff --git a/src/Butin/PieceButin.cpp b/src/Butin/PieceButin.cpp index ef2bd7a..bcdea22 100644 --- a/src/Butin/PieceButin.cpp +++ b/src/Butin/PieceButin.cpp @@ -18,8 +18,7 @@ std::string PieceButin::to_string(const enum Categorie cat) const { return "Noire"; default: - std::cerr << "Catégorie inconnue (PieceButin).\n"; - exit(EXIT_FAILURE); + throw std::logic_error("Catégorie inconnue (PieceButin)."); } } diff --git a/src/Dames/Dames.cpp b/src/Dames/Dames.cpp index f39df7c..16c38a9 100644 --- a/src/Dames/Dames.cpp +++ b/src/Dames/Dames.cpp @@ -56,8 +56,7 @@ bool Dames::prisePossible(Joueur &joueur) const { for (uint i = 0; i < pieces.size(); i++) { PieceDames *p = dynamic_cast(pieces[i]); if (!p) { - std::cerr << "Cette pièce est.. étrange.\n"; - exit(EXIT_FAILURE); + throw std::runtime_error("Cette pièce est.. étrange."); } if (p->getDame()) { // if(plateau[x][y] == nullptr) diff --git a/src/Dames/PieceDames.cpp b/src/Dames/PieceDames.cpp index fa5ecef..6762f20 100644 --- a/src/Dames/PieceDames.cpp +++ b/src/Dames/PieceDames.cpp @@ -23,8 +23,7 @@ std::string PieceDames::to_string(const enum Categorie cat) const { return "Noire"; default: - std::cerr << "Catégorie inconnue (PieceDames).\n"; - exit(EXIT_FAILURE); + throw std::logic_error("Catégorie inconnue (PieceDames)."); } } diff --git a/src/Ecran.cpp b/src/Ecran.cpp index b2f0312..6e326f1 100644 --- a/src/Ecran.cpp +++ b/src/Ecran.cpp @@ -9,7 +9,14 @@ std::string Ecran::message = ""; bool Ecran::fps = false; +int Ecran::count = 0; + Ecran::Ecran(const uint w, const uint h, const std::string n, const bool pf) { + if (count >= 1) { + throw std::logic_error("Uniquement 1 écran supporté."); + } + ++count; + // Création de la fenêtre SFML window.create(sf::VideoMode(w, h + bottomTxtPadding), n, sf::Style::Titlebar | sf::Style::Close); @@ -17,7 +24,9 @@ Ecran::Ecran(const uint w, const uint h, const std::string n, const bool pf) { fps = pf; } -Ecran::~Ecran() {} +Ecran::~Ecran() { + --count; +} void Ecran::afficher( const std::function dessin, diff --git a/src/Safari/PieceSafari.cpp b/src/Safari/PieceSafari.cpp index 19a15c0..9b82c5c 100644 --- a/src/Safari/PieceSafari.cpp +++ b/src/Safari/PieceSafari.cpp @@ -20,8 +20,7 @@ std::string PieceSafari::to_string(const enum Categorie cat) const { return "Lion"; default: - std::cerr << "Catégorie inconnue (PieceSafari).\n"; - exit(EXIT_FAILURE); + throw std::logic_error("Catégorie inconnue (PieceSafari)."); } }