-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (46 loc) · 1.32 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (46 loc) · 1.32 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
#include "game.hpp"
#include "screen.hpp"
#include "window.hpp"
#include <stdexcept>
std::tuple<int,int> get_max_y_x() {
int y,x;
getmaxyx(stdscr,y,x);
return {y,x};
}
int main(int argc, char** argv)
{
if (argc == 2) {
auto opt = std::string(argv[1]);
if (opt == "--version" || opt == "-v") {
std::cout << "quick snake version 1.0\n";
std::cout << "https://www.github.com/gregstula/quick-snake" << std::endl;
return 0;
}
}
uint64_t score = 0;
try {
auto screen = curses::screen();
curses::refresh_guard<curses::screen> refresh(screen);
auto&& [y,x] = get_max_y_x();
// standard game is 80x40 but we will still
// try to get ok dimensions on smaller screens with small fonts etc
int dimx = 80;
if (x <= 80) {
dimx = x - (80 - x);
if (dimx % 2 != 0) dimx--;
}
int dimy = dimx/2;
while (dimy > y - 6) { // account for score menu size
dimx -= 2;
dimy = dimx/2;
}
auto game = snake_game::game(dimy,dimx);
score = game.game_loop();
}
catch (std::exception& err) {
std::cerr << err.what() << std::endl;
return -1;
}
std::cout << "Score: " << score << std::endl;
return 0;
}