aboutsummaryrefslogtreecommitdiff
path: root/frontend/main.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
commitb20f46c15dce8b196dbb8890890978947745e094 (patch)
treed9defa84717ffa843fd11b05d0e856473d6d8d59 /frontend/main.cpp
parenta7e84b60366c78b131d43157980fbe4c2df655e6 (diff)
change flow architecture
Diffstat (limited to 'frontend/main.cpp')
-rw-r--r--frontend/main.cpp57
1 files changed, 2 insertions, 55 deletions
diff --git a/frontend/main.cpp b/frontend/main.cpp
index f8e2526..64b4474 100644
--- a/frontend/main.cpp
+++ b/frontend/main.cpp
@@ -1,70 +1,17 @@
-#include <cstdlib>
-#include <cstdio>
-#include <memory>
-
#include "backend/print.h"
-#include "backend/Dungeon.h"
-#include "GameData.h"
#include "GameController.h"
#include "Exception.h"
-#include "load_dungeon.h"
-#include "generate_dungeon.h"
-#include "rl.h"
-#include "strings.h"
using namespace std;
-static unique_ptr<Dungeon> 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> dungeon = make_dungeon();
- GameController game { *dungeon };
-
- while (1) {
- string line = rl();
- if (line.length() == 0) continue;
- FollowupAction action = game.cmd(line);
-
- switch (action) {
- case NONE: break;
- case UPDATE: {
- dungeon->update();
- break;
- }
- default: return action;
- }
- }
-}
-
int main() {
try {
- GameData::get_instance(); // pre-load DB
+ GameController game;
+ return game.main();
} 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;
}