2048-homework/src/main.c

55 lines
1.4 KiB
C
Raw Permalink Normal View History

2021-11-15 08:57:27 +00:00
#include "2048.h"
2021-12-14 20:26:10 +00:00
#include "gui.h"
#include "tui.h"
2021-11-15 08:57:27 +00:00
2021-12-14 20:26:10 +00:00
int main(int argc, char *argv[]) {
2021-12-14 21:02:07 +00:00
bool tui = false;
int size_x = 4;
int size_y = 4;
2021-12-27 18:14:44 +00:00
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--help")) {
2021-12-27 18:14:44 +00:00
printf("You can pass following arguments: \n--help, \n--tui (not all ui elements are implemented, only for demonstration), \n--x (width, default 4), \n--y (height, default 4)\n");
return 0;
}
2021-12-27 18:14:44 +00:00
else if (!strcmp(argv[i], "--tui")) {
2021-12-14 21:02:07 +00:00
tui = true;
}
2021-12-27 18:14:44 +00:00
else if (!strcmp(argv[i], "--x")) {
2021-12-14 21:02:07 +00:00
if (argc >= i) {
2021-12-14 21:52:53 +00:00
if(sscanf(argv[i+1], "%d", &size_x) != 1){
printf("invalid input\n");
return 1;
}
2021-12-27 18:14:44 +00:00
i++;
2021-12-14 21:02:07 +00:00
}
}
2021-12-27 18:14:44 +00:00
else if (!strcmp(argv[i], "--y")) {
2021-12-14 21:02:07 +00:00
if (argc >= i) {
2021-12-14 21:52:53 +00:00
if(sscanf(argv[i+1], "%d", &size_y) != 1){
printf("invalid input\n");
return 1;
}
2021-12-27 18:14:44 +00:00
i++;
2021-12-14 21:02:07 +00:00
}
}
2021-12-27 18:14:44 +00:00
else {
printf("invalid input \"%s\"\n", argv[i]);
return 1;
}
2021-12-14 21:02:07 +00:00
}
2021-11-15 08:57:27 +00:00
Game game;
2021-12-14 21:02:07 +00:00
game = game_init(size_x, size_y);
if (tui) {
tui_init();
tui_loop(&game);
tui_destroy();
}
else {
gui_init();
gui_loop(&game);
gui_destroy();
}
2021-12-24 13:02:00 +00:00
game_destroy(&game);
2021-11-15 08:57:27 +00:00
return 0;
}