blob: 536c07d5ef7ab6ac16ec830f794766af35abbc4e (
plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <string.h>
#include <time.h>
#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;
}
|