#include #include #include #include "backend/print.h" #include "backend/Dungeon.h" #include "GameData.h" #include "Player.h" #include "Exception.h" #include "load_dungeon.h" #include "generate_dungeon.h" #include "rl.h" #include "strings.h" using namespace std; static unique_ptr make_dungeon() noexcept { while (1) { str_print(strings::INTRO); string filename = rl(); try { if (filename.size() == 0) { return generate_dungeon(); } else { return load_dungeon(filename); } } catch (Exception & e) { lprtf("FOUT: %s\n", e.what()); } } } FollowupAction game_main() { unique_ptr dungeon = make_dungeon(); Player player { *dungeon }; while (1) { string line = rl(); if (line.length() == 0) continue; FollowupAction action = player.cmd(line); switch (action) { case NONE: break; case UPDATE: { dungeon->update(&player.get_location()); break; } default: return action; } } } int main() { try { GameData::get_instance(); // pre-load DB } catch (Exception & e) { lprtf("FOUT: %s\n", e.what()); return EXIT_FAILURE; } FollowupAction action; do { action = game_main(); if (action == EXIT) break; } while (action == RESTART); return EXIT_SUCCESS; }