blob: deacdc56de9dcb568d187ee9b0d5b6712eb8a013 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <cstdlib>
#include <cstdio>
#include <memory>
#include "backend/Dungeon.h"
#include "Player.h"
#include "Exception.h"
#include "print.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();
Player player { *dungeon };
while (1) {
string line = rl();
if (line.length() == 0) continue;
vector<string> argv = str_split(line, " ");
FollowupAction action = player.cmd(argv);
switch (action) {
case NONE: break;
case UPDATE: {
dungeon->update();
break;
}
default: return action;
}
}
}
int main() {
FollowupAction action;
do {
action = game_main();
if (action == EXIT) break;
} while (action == RESTART);
return EXIT_SUCCESS;
}
|