-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.h
63 lines (47 loc) · 1.93 KB
/
board.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
/*
* Defines all the necessary functions and structs to keep track of the various
* blocks onscreen.
*/
#ifndef TETRIS_BOARD
#define TETRIS_BOARD
#include <curses.h>
#include <stdbool.h>
#include "piece.h"
/* Board struct. Contains width, height, board contents, and the current piece
* that is being manipulated by the player. */
typedef struct Board {
int width;
int height;
unsigned char* board;
Piece* piece;
bool *cleared;
} Board;
/* Gets the index from the x and y coordinates based on width. */
#define COORD_INDEX(board, x, y) (x) + (board->width * (y))
/* Initializes a board of the specified dimensions. */
Board* board_init(int width, int height);
/* Frees a board. Returns true on success. */
void board_free(Board* boardPtr);
/* Sets the current falling piece. */
void board_setPiece(Board* boardPtr, enum PieceType type);
/* Determines if line <line> is completely full. */
bool board_isLineFull(Board* boardPtr, int line);
/* Clears a line on the board. (Note: does not shift down after clearing. */
void board_setCleared(Board* boardPtr, int line);
/* Attempts to move the piece by the specified coordinates. Returns true if it
* is a valid move. */
bool board_movePiece(Board* boardPtr, int x, int y);
/* Attempts to rotation the piece by the specified coordinates. Returns true if
* it is a valid rotation. */
bool board_rotatePiece(Board* boardPtr, bool counter);
/* "Cements" the current piece onto the board. Called when a block falls to its
* lowest point. */
void board_cementPiece(Board* boardPtr);
/* Draws the board on the specified window at (0,0). Returns true on success. */
void board_draw(Board* boardPtr, WINDOW* subWin, bool showProjection);
/* Draw the board with recently cleared lines flashing. Clears and shifts those
* lines afterwards. */
void board_clearLines(Board* boardPtr, WINDOW* subWin, unsigned int delay, int count);
/* Clears the board. */
void board_clear(Board* boardPtr);
#endif