-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (43 loc) · 1.36 KB
/
main.cpp
File metadata and controls
57 lines (43 loc) · 1.36 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
51
52
53
54
55
56
57
#include <iostream>
#include <fstream>
#include <sys/ioctl.h>
#include <ncurses.h>
#include <unistd.h>
#include "game.h"
bool is_screen_large_enough() {
int row_cnt, col_cnt;
getmaxyx(stdscr, row_cnt, col_cnt);
if (SNAKE_GAME_DEBUG)
fprintf(stdout, "Expected %dx%d got %dx%d\n", SNAKE_GAME_MIN_FRAME_HEIGHT, SNAKE_GAME_MIN_FRAME_WIDTH, row_cnt,
col_cnt);
return row_cnt >= SNAKE_GAME_MIN_FRAME_HEIGHT && col_cnt >= SNAKE_GAME_MIN_FRAME_WIDTH;
}
int main() {
initscr();
noecho();
cbreak();
nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
curs_set(FALSE);
int _res = 0;
int row_cnt, col_cnt;
getmaxyx(stdscr, row_cnt, col_cnt);
log << "Height=" << row_cnt << " Width=" << col_cnt << std::endl;
if (is_screen_large_enough()) {
try {
log << "File: " << __FILE__ << " Line: " << __LINE__ << std::endl;
log << "File: " << __FILE__ << " Line: " << __LINE__ << std::endl;
Game game;
_res = game.run();
log << "File: " << __FILE__ << " Line: " << __LINE__ << std::endl;
} catch (const std::exception &e) {
endwin(); // Restore normal terminal behavior
throw e;
return 1;
}
} else {
std::cerr << "Screen is not large enough!" << std::endl;
}
endwin();
return _res;
}