aboutsummaryrefslogtreecommitdiff
path: root/frontend/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/main.cpp')
-rw-r--r--frontend/main.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/frontend/main.cpp b/frontend/main.cpp
index b9322ee..c421d9e 100644
--- a/frontend/main.cpp
+++ b/frontend/main.cpp
@@ -3,25 +3,35 @@
#include <memory>
#include "backend/Dungeon.h"
-#include "Player.h"
+#include "Player.h"
+#include "Exception.h"
+#include "frontend/print.h"
+#include "load_dungeon.h"
+#include "generate_dungeon.h"
#include "rl.h"
#include "strings.h"
-#include "print.h"
using namespace std;
-FollowupAction game_main() {
- auto dungeon = make_unique<Dungeon>();
-
- print_string(strings::INTRO);
- string filename = rl();
- if (filename.size() == 0) {
- lprtf("TODO: generate dungeon\n");
- } else {
- lprtf("TODO: load %s\n", filename.c_str());
+static unique_ptr<Dungeon> make_dungeon() noexcept {
+ while (1) {
+ print_string(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> dungeon = make_dungeon();
Player player { *dungeon };
while (1) {