#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+1, posY, posX+1, BORDER_GAP, RAYWHITE);
}

void drawSquare(int x, int y, Color color){
    DrawRectangle(BORDER_GAP + x*SQUARE_SIZE,
                BORDER_GAP + y*SQUARE_SIZE,
                SQUARE_SIZE,
                SQUARE_SIZE,
                color);
    
    
}

void drawPiece(Piece p){
    for(int i = 0; i < p.size; i++){
        drawSquare(p.squares[i]->posX, p.squares[i]->posY, p.squares[i]->color);
    }
}

void drawGrid(Grid g){
    for(int x = 0; x < g.width; x++){
        for(int y = 0; y < g.height; y++){
            if(g.grid[x][y] != NULL){
                drawSquare(x, y, g.grid[x][y]->color);
            }
            //drawSquare(g.grid[x][y]);
        }
    }
}

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

    drawPiece(piece);

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

    addPieceToGrid(piece, grid);
}