from modules.config import Configurations

class Score(Configurations):
    """
    This class maintains the score of the player, the cleared lines and the current level
    """

    score = 0
    level = 1 
    cleared_lines = 0
    tetris_count = 0

    def __init__(self, level=None):

        # Futureproofing: allows user start from a given level:
        if level:
            self.level = level

        self.scoring_multiplier = self.scoring['multiplier']
        self.soft_drop_score = self.scoring['soft_drop_score']
        self.hard_drop_score = self.scoring['hard_drop_score']

    def rows_cleared(self, rows_cleared=None):
        """
        Takes the number of rows cleared and calculates the score
        """

        if rows_cleared is None or rows_cleared == 0    :
            return

        if rows_cleared == 4:
            self.tetris_count += 1

        # If at least one row is cleared:
        self.cleared_lines += rows_cleared

        self.score += self.scoring_multiplier[rows_cleared] * self.level

        # Testing if we go to the next level:
        if int(self.cleared_lines / 10) >= self.level:
            self.level += 1


    def add_hard_drop_score(self, drops):

        if drops is not None:
            self.score += self.hard_drop_score * drops


    def get_level(self):
        return self.level


    def get_score(self):
        return self.score


    def get_rows(self):
        return self.cleared_lines


    def get_tetris_rate(self):
        if self.cleared_lines == 0:
            return 0
        else:
            return int((self.tetris_count * 4 / self.cleared_lines)*100)



