-
Notifications
You must be signed in to change notification settings - Fork 1
/
tetris.c
59 lines (45 loc) · 1.03 KB
/
tetris.c
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "board.h"
#include "piece.h"
#include "console.h"
#include "input.h"
#include "errors.h"
#include "graphics.h"
#include "timer.h"
#define BOARD_WIDTH 10
#define BOARD_HEIGHT 20
int main(void)
{
console_t console;
console_init(&console);
board_t board;
board_init(&board, BOARD_WIDTH, BOARD_HEIGHT);
piece_init();
if (input_init() != SUCCESS) {
printf("ERROR: failed to initialize input thread!\n");
exit(1);
}
timer_init(&board);
graphics_update(&board);
bool gameover = false;
while (!gameover) {
board_newpiece(&board);
timer_resume();
while (!timer_anchored()) {
keycode_t input = input_pop();
piece_hide(&board);
input_handle(&board, input);
piece_show(&board);
graphics_update(&board);
}
board_linecheck(&board);
graphics_update(&board);
gameover = board_gameover(&board);
}
printf("\n***** GAME OVER!! *****\n");
board_destroy(&board);
console_destroy(&console);
return 0;
}