# 專案-俄羅斯方塊
## 俄羅斯方塊需求
下面會列出完成專案需要的 define 、物件(結構)、函式及其參數、回傳值與功能,由你們完成這些函式的實作。
### enum - Color
顏色
```c=
typedef enum {
RED = 41,
GREEN,
YELLOW,
BLUE,
PURPLE,
CYAN,
WHITE,
BLACK = 0,
}Color;
```
### enum - ShapeId
方塊形狀對應ID
```c=
typedef enum {
EMPTY = -1,
I,
J,
L,
O,
S,
T,
Z
}ShapeId;
```
### struct - Shape
7種方塊的資料(形狀ID、顏色、大小、選轉的樣式)
```c=
typedef struct {
ShapeId shape;
Color color;
int size;
char rotates[4][4][4];
}Shape;
```
### struct - State
遊戲的狀態(分數、座標位置、旋轉模式、掉落時間、QUEUE裡的方塊是?)
```c=
typedef struct {
int x;
int y;
int score;
int rotate;
int fallTime;
ShapeId queue[4];
}State;
```
### struct - Block
遊戲版上的方塊
```c=
typedef struct {
Color color;
ShapeId shape;
bool current;
}Block;
```
透過二維陣列去表達
```c=
Block canvas[CANVAS_HEIGHT][CANVAS_WIDTH];
```
### void setBlock()
設置遊戲版上的方塊
```c=
void setBlock(Block* block, Color color, ShapeId shape, bool current)
{
block->color = color;
block->shape = shape;
block->current = current;
}
```
### void resetBlock()
將遊戲版上的方塊設為預設值
```c=
void resetBlock(Block* block)
{
block->color = BLACK;
block->shape = EMPTY;
block->current = false;
}
```
### void printCanvas()
寫一個函式負責輸出我們的遊戲板內容,這樣在 main 裡面比較容易讀懂,也能更好去做修改
```c=
void printCanvas(Block canvas[CANVAS_HEIGHT][CANVAS_WIDTH], State* state)
{
printf("\033[0;0H\n");
for (int i = 0; i < CANVAS_HEIGHT; i++) {
printf("|");
for (int j = 0; j < CANVAS_WIDTH; j++) {
printf("\033[%dm\u3000", canvas[i][j].color);
}
printf("\033[0m|\n");
}
return;
}
```
### bool move()
嘗試移動新座標,若有超出標界回傳 false ,若無會更新 Block 的方塊至新的位置
```c=
bool move(遊戲板,原本X,原本Y,原本旋轉模式,新的X,新的Y,新的旋轉模式,形狀ID){
1. 判斷是否新座標會撞到邊界
2. 若沒有撞到邊界,重新reset整個 Block,set新座標上去 Block
}
```
### void logic()
截至第三周,負責呼叫 move() 去判斷是否該移動方塊向下一格
```c=
void logic(Block canvas二維,State* state)
{
if (move()成立)
y座標++
return;
}
```
### int clearLine()