From 556a1d1866134a60a55de055bb9713c0bdfdb936 Mon Sep 17 00:00:00 2001 From: Baptiste Pouget Date: Sun, 14 May 2017 18:24:15 +0200 Subject: [PATCH] Added better args --- src/main.cpp | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 95cb37a..4e6531d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ * \brief Beginning of the project titled "Sokochez" * A Sokoban multiplayer clone */ - +#include #include #include #include @@ -16,25 +16,40 @@ using namespace std; int main (int argc, char *argv[]) { + vector flagsPos; + bool editor; + bool help; set_input_mode (); - if ((argc < 2) || (("-e" == (string) argv[1]) && (argc < 3))) + + for (int i = 1; i < argc; ++i) { - cerr << "Argument(s) missing : At least one map file name required" << endl; - return 0; + if (argv[i][0] == '-') + flagsPos.push_back(i); + if ((string) argv[i] == "-e") + editor = true; + if ((string) argv[i] == "-h") + help = true; } - if ("-e" == (string) argv[1]) + + if (help) { - for (int i (2); i < argc; ++i) - { - Editor (argv[i]); - } + cout << "Sokochez Help" << endl + << "Usage : [flags] level[s]" << endl + << "-e : editor mode " << endl + << "-h : print help " << endl; + return 0; } - else + + for (int i = 1; i < argc; ++i) { - for (int i (1); i < argc; ++i) - { - Game (argv[i]); - } + if (find(flagsPos.begin(), flagsPos.end(), i) != flagsPos.end()) + continue; + if (editor) + Editor(argv[i]); + else + Game(argv[i]); } + + cout << "No more levels." << endl; return 0; }