From f831f3cd92cc0fa8b7e1000abe317e553678f008 Mon Sep 17 00:00:00 2001 From: Rudi Date: Mon, 5 Oct 2020 02:31:48 +0000 Subject: [PATCH] Updates to use flags instead of positional arguments --- .gitignore | 0 Game.cpp | 41 ++++++++++++++++++++--------------------- stories/first.csv | 0 3 files changed, 20 insertions(+), 21 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 Game.cpp mode change 100644 => 100755 stories/first.csv diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Game.cpp b/Game.cpp old mode 100644 new mode 100755 index 5088092..8505ef7 --- a/Game.cpp +++ b/Game.cpp @@ -26,23 +26,25 @@ string game_csv; level GotoLevel(int); int main(int argc, char **argv) { - // Refuse to start without at least a game_csv - if (argc != 2) { - game_csv = "/ftp/pub/users/rudi/CSVGame/story.csv"; - } else { - // Set global game_csv - game_csv = argv[1]; - } // Initialize nextLevel to 0 (load first level) - int nextLevel = 0; - // If user supplied a level - if (argc == 3) { - // override nextLevel with that level - nextLevel = atoi(argv[2]); + int next_level = 0; + game_csv = "/sys/sdf/share/csvgame/story.csv"; + for (int i = 1; i < argc; i++) { + string test_arg = string(argv[i]); + if (test_arg == "-f") { + if (argc > i+1) { + game_csv = string(argv[i+1]); + } + } + if (test_arg == "-l") { + if (argc > i+1) { + next_level = atoi(argv[i+1]); + } + } } - - // Setup the level from nextLevel - level l = GotoLevel(nextLevel); + + // Setup the level from next_level + level l = GotoLevel(next_level); while(l.choiceIDs.size() > 0) { // Display the level info cout << endl << l.id << "\t" << l.title << endl << endl << l.body << endl <> nextLevel; - } while (!count(l.choiceIDs.begin(), l.choiceIDs.end(), nextLevel)); - l = GotoLevel(nextLevel); + cin >> next_level; + } while (!count(l.choiceIDs.begin(), l.choiceIDs.end(), next_level)); + l = GotoLevel(next_level); } } - level GotoLevel(int num) { // Read file, from the global game_csv converted to a C string (const char array) fstream file(game_csv.c_str()); @@ -101,6 +102,4 @@ level GotoLevel(int num) { line.erase(0, line.find(separator) + separator.length()); } return l; - - } diff --git a/stories/first.csv b/stories/first.csv old mode 100644 new mode 100755