-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
90 lines (57 loc) · 1.7 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#define _XOPEN_SOURCE_EXTENDED
#include <ncursesw/ncurses.h>
#include <string>
#include <iostream>
#include <filesystem>
#include <fstream>
#include <events/dispatcher.h>
#include <events/events.h>
#include <game/game.h>
#include <grid/grid.h>
#include <menu/menu.h>
#include <menu/opts.h>
#include <ui/ui.h>
#include <io.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
Game main_game;
main_game.start();
WINDOW *main_window = initscr();
start_color();
int w, h;
curs_set(0);
TextBanner title_banner("assets/banner");
Menu menu(&title_banner);
if (filesystem::exists("save"))
menu.add_option("Continue", new ContinueOption(&main_game));
menu.add_option("New game", new GoToOption(&main_game, "diff"));
menu.add_option("Exit", new ExitOption(&main_game));
Menu diff_menu(&title_banner);
diff_menu.add_option("Easy", new NewGameOption(&main_game, D_EASY));
diff_menu.add_option("Medium", new NewGameOption(&main_game, D_MEDIUM));
diff_menu.add_option("Hard", new NewGameOption(&main_game, D_HARD));
diff_menu.add_option("Back", new GoToOption(&main_game, "main"));
main_game.add_menu("main", &menu);
main_game.add_menu("diff", &diff_menu);
EventDispatcher<KeyboardEvent> keyboard;
keyboard.subscribe(main_game.on_key_press);
EventDispatcher<RenderEvent> renderer;
renderer.subscribe(main_game.on_render);
while (main_game.is_running())
{
clear();
getmaxyx(main_window, h, w);
renderer.notify(new RenderEvent(w, h, w / 2, h / 4));
refresh();
attron(A_INVIS);
int c = getch();
keyboard.notify(new KeyboardEvent(c));
attroff(A_INVIS);
}
attroff(A_INVIS);
curs_set(1);
endwin();
return 0;
}