-
Notifications
You must be signed in to change notification settings - Fork 1
/
tetris.h
85 lines (69 loc) · 1.37 KB
/
tetris.h
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
80
81
82
83
84
85
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <curses.h>
#include <iostream>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <vector>
#define GRID_START 6
#define GRID_END 47
#define SCORE_X 4
#define SCORE_Y 2
#define HOLD_X 6
#define HOLD_Y 7
#define LEVEL_X 5
#define LEVEL_Y 25
#define GOAL_X 6
#define GOAL_Y 36
#define NEXT_X 85
#define NEXT_Y 7
#define X_OFFSET 28
#define Y_OFFSET 7
#define CENTER 54
#define BUFFER 3
typedef enum {LEFT, RIGHT, DOWN} direction;
typedef enum {
EMPTY, I_BLOCK, J_BLOCK, L_BLOCK, O_BLOCK, S_BLOCK, Z_BLOCK, T_BLOCK, DEFAULT
} tetromino;
typedef struct Piece {
int x;
int y;
} Piece;
typedef struct Block {
tetromino type;
int state;
Piece a;
Piece b;
Piece c;
Piece d;
} Block;
int weights[7];
WINDOW * mainwin;
bool initialized = false;
int debug = 0;
int speed = 1000000; //FLAWED... Sec vs uSec
int grid[20][10];
Block block;
void initGame();
void mainLoop();
void closeGame();
bool canMove(direction dir);
void alarm_wakeup (int i);
void redraw();
bool move(direction);
void print(int x, int y, const char* message);
bool isFilled(Piece, int);
void color(int);
void setColors(bool);
void emptyGrid();
void clearLines();
int pseudoRandom();
void space();
void rotate();
void printGrid();
void printBlocks();
void printWeights();
void refreshBlock();
void updateGrid();