"""
------------------------------------------------------------------------------
--                                                                          --
--                               PROJECT 02                                 --
--                                                                          --
--                      D R A W _ P A C K I N G . P Y                       --
--                                                                          --
------------------------------------------------------------------------------
-- <Your Name Here>                                                         --
--                                                                          --
-- <Class Name Here>                                                        --
--                                                                          --
------------------------------------------------------------------------------
-- This file contains drawing functions for Project 2                       --
--                                                                          --
------------------------------------------------------------------------------
"""

class GameView:
    """
    A Game is a Frame with a canvas for drawing a Tetris board.  It takes a
    reference (alias) to a list of shapes that are on the board, and a size
    in rows and columns.
    """
    def __init__(self, rows, cols, shapes_list):
        self.rows = rows
        self.cols = cols
        self.blank_board()

        self.shapes = shapes_list

        for shape in self.shapes:
            self.draw_shape(shape)

    def blank_board(self):
        self.game_board = []
        for row in range(self.rows):
            self.game_board.append([" "] * self.cols)

    def draw_square(self, x, y, letter):
        """
        Draws on self a square in GRID location x, y.  Keep in mind that a grid
        location (and therefor each square) is 20 by 20 pixels.
        """
        self.game_board[y][x] = letter

    def draw_shape(self, shape):
        """
        Draws shape on self
        calls: draw_square
        """
        for row in range(len(shape.squares)):
            for col in range(len(shape.squares[row])):
                if shape.squares[row][col]:
                    self.draw_square(
                        shape.x + col,
                        shape.y + row,
                        shape.letter)

    def draw_game_board(self):
        """
        Draws the entire game board.  This can be done by simply using self's
        alias to the list of shapes on the board.
        calls: draw_shape.
        """
        self.blank_board()

        for shape in self.shapes:
            self.draw_shape(shape)

        print('*' * (self.cols + 2))
        for row in range(self.rows):
            row_string = ''
            for col in range(self.cols):
                row_string += self.game_board[row][col]
            print('*' + row_string + '*')
        print('*' * (self.cols + 2))
