-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
66 lines (58 loc) · 2.35 KB
/
game.cpp
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
65
66
#include <map>
#include <string>
namespace crs {
#include <ncurses.h>
}
#include "behavior.hpp"
#include "window.hpp"
#include "game.hpp"
void Game::draw_main_menu(Window& mm_window) {
for(int n=0; n < 255; ++n) {
mm_window.p("A");
}
}
Game::Game(Window& starting_window) : main_menu(starting_window) {
// Ok this one is going to be a dozy.
// This constructor is going to initalize ALL THE THINGS.
// There's no way around that.
// It could potentially take a noticable amount of time to initialize all the things.
// However we are still going to have the initalization block the rest of the program.
// Opening the ansync thread of worms is NOT worth it.
// The only advantage would be that the user could screw around on the menu before the game is loaded.
// There's nothing of substance you can do before the game is loaded anyway.
// So accepting keyboard input before the game is loaded really is no big deal.
// What we can do, is have multiple refreshes take place during this call.
// Using this we can have a loading bar type thing down the line potentially.
// Other operations (worldgen etc) could also potentially take a noticable amount of time to run.
// Those operations will be refered here, which is where the approach behind non instant stuff is detailed.
draw_main_menu(main_menu);
// Calls to refresh are done explicitly outside of drawing functions.
// Having refreshes inside of drawing functions would make drawing animations and similar possible.
// However animations of that sort would block input, which would make the game feel a lot less responsive.
// Calling refresh inside of a drawing function could lead to a situation like this:
// Crawl's auto explore by default will animate every frame.
// This sounds nice and you see an animation of your character exploring.
// In practice though, it slows down gameplay a lot, and I disable it every time.
// Code to disable it could be hard though if we have refresh calls all over the place.
main_menu.refresh();
}
void Game::run(Behavior action) {
switch(action) {
case QUIT_GAME: {
crs::endwin();
break;
}
case DO_NOTHING: {
break;
}
case MENU_UP: {
//main_menu.p("h");
main_menu.refresh();
break;
}
default: {
throw std::runtime_error("Behavior not implemented.");
return;
}
}
}