From 6a6144e35eef47edd6ec20c3501a504521ddd0b1 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 28 Dec 2023 15:44:04 +0100 Subject: [PATCH] add cli interface --- src/main.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0ab90ba..7eb9f71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ +#include "../includes/Butin/PlateauButin.hpp" #include "../includes/Dames/PlateauDames.hpp" #include "../includes/Ecran.hpp" +#include "../includes/Safari/PlateauSafari.hpp" -void draw_debug(PlateauDames &p) { +void draw_debug(Plateau &p) { p.afficherPlateau(std::cout, false); } @@ -9,13 +11,70 @@ void click_debug(const int x, const int y) { std::cout << "Clic souris @ (" << x << ", " << y << ")\n"; } -int main() { - Joueur j1; - Joueur j2; - PlateauDames p(j1, j2); - Ecran e; - // e.afficher(std::bind(&draw_debug, p), click_debug); +void help(char const *progName) { + std::cout << "Menu d'aide de " << progName << "\n"; + + std::cout << "\t" << progName << " butin\n"; + std::cout << "\t\t" + << "Lance le jeu \"Butin\"\n"; + + std::cout << "\t" << progName << " dames\n"; + std::cout << "\t\t" + << "Lance le jeu \"Dames\"\n"; + + std::cout << "\t" << progName << " safari\n"; + std::cout << "\t\t" + << "Lance le jeu \"Safari\"\n"; +} + +int main(int argc, char const *argv[]) { + Ecran e; + + // Interface cli + if (argc >= 2) { + Joueur j1; + + std::string arg = argv[1]; + Plateau *p; + if (arg.compare("help") == 0) { + help(argv[0]); + + return EXIT_SUCCESS; + } + + else if (arg.compare("butin") == 0) { + Joueur j2; + p = new PlateauButin(); + } + + else if (arg.compare("dames") == 0) { + Joueur j2; + p = new PlateauDames(j1, j2); + } + + else if (arg.compare("safari") == 0) { + Joueur j2; + Joueur j3; // demander à l'utilisateur + p = new PlateauSafari(); + } + + else { + std::cerr << "Jeu inconnu.\n"; + help(argv[0]); + + return EXIT_FAILURE; + } + + e.afficher(std::bind(&draw_debug, std::ref(*p)), click_debug); + + // Libère le plateau de la mémoire + delete p; + + std::cout << "Merci d'avoir joué !" << std::endl; + } else { + // Interface graphique, menu de selection de jeu ? + help(argv[0]); + } - std::cout << "Good bye!" << std::endl; return EXIT_SUCCESS; }