summaryrefslogtreecommitdiff
path: root/tetris.c
diff options
context:
space:
mode:
Diffstat (limited to 'tetris.c')
-rw-r--r--tetris.c86
1 files changed, 45 insertions, 41 deletions
diff --git a/tetris.c b/tetris.c
index 8f8b43f..536c07d 100644
--- a/tetris.c
+++ b/tetris.c
@@ -14,62 +14,66 @@
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 interrupt_handler(int sig)
+{
+ UNUSED(sig);
+ g_int_ctrl_c = 1;
}
-void parse_args(int argc, char **argv) {
+void parse_args(int argc, char **argv)
+{
}
-void display_game(void) {
+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;
+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);
+ /* 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);
+ /* 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);
+ /* handle SIGINT interrupts */
+ signal(SIGINT, interrupt_handler);
- /* Hide cursor */
- print("\033[?251");
+ /* 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;
+ /* 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();
+ /* 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");
+ /* 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;
+ /* free some values */
+ free(cancellation_token);
+ free((int *) last_input);
+ return 0;
}