#include #include #include #include #include #include #include "tetris.h" #include "conio.h" #include "vector.h" #include "block.h" #define UNUSED(x) (void)(x) volatile sig_atomic_t g_int_ctrl_c = 0; int g_score = 0; void interrupt_handler(int sig) { UNUSED(sig); g_int_ctrl_c = 1; } void parse_args(int argc, char **argv) { } void display_game(void) { } int main(int argc, char **argv) { int width; int height; volatile int *last_input = calloc(1, sizeof(int)); int *cancellation_token = calloc(1, sizeof(int)); struct winsize win; struct timespec time; /* store arguments in global variables */ parse_args(argc, argv); /* get dimensions of board */ ioctl(fileno(stdout), TIOCGWINSZ, &win); width = (int) (win.ws_col); height = (int) (win.ws_row); /* handle SIGINT interrupts */ signal(SIGINT, interrupt_handler); /* Hide cursor */ print("\033[?251"); /* prepare thread for getting input and accepting cancellation */ thread_arg_t *thread_arg = malloc(sizeof(thread_arg_t)); thread_arg->ret = (void *) last_input; thread_arg->cancellation_token = cancellation_token; /* Game Loop */ while (1) { if (g_int_ctrl_c) { goto EXIT; } display_game(); } EXIT: /* cancel thread */ *cancellation_token = 1; printf("%sGame over! Your score was: %d%s\n", RED, g_score, COLOR_RESET); /* unhide cursor */ printf("\033[?25h"); /* free some values */ free(cancellation_token); free((int *) last_input); return 0; }