From 0f726414cc0026691854bda9567ef959c7a2a976 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Mon, 6 Feb 2023 22:55:20 -0800 Subject: added new stuff --- tetris.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'tetris.c') diff --git a/tetris.c b/tetris.c index 88a99f3..8f8b43f 100644 --- a/tetris.c +++ b/tetris.c @@ -3,7 +3,12 @@ #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; @@ -17,20 +22,54 @@ void interrupt_handler(int sig) { void parse_args(int argc, char **argv) { } -void die(void) { +void display_game(void) { } + int main (int argc, char **argv) { - parse_args(argc, 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; } -- cgit v1.3.1