#include "tetris-graph.h"

void InitGame(){
    InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Tetris");
    SetTargetFPS(60);
}

void InitDisplay(){
    ClearBackground(BLACK);

    const int posY = BORDER_GAP+GRID_PHEIGHT;
    const int posX = BORDER_GAP+GRID_PWIDTH;

    DrawLine(BORDER_GAP, BORDER_GAP, BORDER_GAP, posY, RAYWHITE);
    DrawLine(BORDER_GAP, posY, posX, posY, RAYWHITE);
    DrawLine(posX, posY, posX, BORDER_GAP, RAYWHITE);
}

void drawSquare(Square sq){
    if(sq != NULL){
        DrawRectangle(BORDER_GAP + sq->posX*SQUARE_SIZE,
                      BORDER_GAP + sq->posY*SQUARE_SIZE,
                      SQUARE_SIZE,
                      SQUARE_SIZE,
                      sq->color);
    }
    
}

void drawPiece(Piece p){
    for(int i = 0; i < p.size; i++){
        drawSquare(p.squares[i]);
    }
}

void displayGrid(Grid g){
    for(int i = 0; i < g.width; i++){
        for(int j = 0; j < g.height; j++){
            drawSquare(g.grid[i][j]);
        }
    }
}

void gameInstructions(Grid grid, Piece* pList){
    Piece piece = generePiece(pList);

    drawPiece(piece);

    while(canMove(piece, grid)){
        movePieceVert(piece, 1);
    }

    addPieceToGrid(piece, grid);
}