-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (45 loc) · 1.51 KB
/
Copy pathmain.cpp
File metadata and controls
50 lines (45 loc) · 1.51 KB
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
#include "atomic"
#include "lib/inputUtils.h"
#include "src/game_controller.h"
#include "src/command.h"
#include "src/grid.h"
#include "src/logging.h"
#include <fstream>
#include <unistd.h>
// TODO :
// Accept arrow keys for input
// Add a background
#define __DEBUG
#define BoardX 9
#define BoardY 9
std::atomic<bool> quit(false);
extern std::ofstream tty;
int main() {
graphics::initialize_locales();
Grid grid(BoardX, BoardY, 10);
graphics::Terminal terminal;
GameController* game_controller = GameController::getInstance();
game_controller->setXLimit(BoardX-1);
game_controller->setYLimit(BoardY-1);
std::vector<command::command> commands = game_controller->getCommands();
commands.push_back({'q', [](){quit.store(true);}});
commands.push_back({{'x','\n'}, [&](){grid.discover(game_controller->getX(), game_controller->getY());}});
commands.push_back({'f', [&](){grid.flag(game_controller->getX(), game_controller->getY());}});
#ifdef __DEBUG
using namespace std::chrono_literals;
gameloop::start_logging_thread(terminal, 2000ms);
#endif
while (!quit.load()) {
auto frame = grid.getWString();
terminal.update_keypress();
terminal.draw(frame);
terminal.show_cursor();
terminal.set_box_cursor();
for (auto command : commands) {
command(terminal);
}
auto [xPos, yPos] = grid.getCursorPositionInGrid(game_controller->getX(), game_controller->getY());
terminal.move_cursor_to(xPos, yPos);
}
return 0;
}