Skip to main content Link Menu Expand (external link) Document Search Copy Copied

FRQ No.1 running code • 4 min read

Description

the hacks for all of the frq 1

# Defines a class to represent a game level.
class Level:
    def __init__(self, points, goal_reached):
        # Initializes the level with points and goal status.
        self.points = points
        self.goal_reached = goal_reached

    def get_points(self):
        # Returns the points associated with this level.
        return self.points

    def is_goal_reached(self):
        # Returns whether the goal for this level has been reached.
        return self.goal_reached

# Defines a class to represent a game.
class Game:
    def __init__(self, levels, is_bonus):
        # Initializes the game with a list of levels and whether it's a bonus game.
        self.levels = levels
        self.is_bonus = is_bonus

    def get_score(self):
        # Calculates the total score for the game.
        total_score = 0
        num_levels = len(self.levels)

        for i in range(num_levels):
            level = self.levels[i]

            # Checks if the goal for this level has been reached.
            if level.is_goal_reached():
                if self.is_bonus:
                    # Triple the points for this level if it's a bonus game.
                    total_score += 3 * level.get_points()
                elif i == 0:
                    # Add points for level one if it's a non-bonus game.
                    total_score += level.get_points()
                elif i == 1 and self.levels[i - 1].is_goal_reached():
                    # Add points for level two if level one goal is reached in a non-bonus game.
                    total_score += level.get_points()
                elif i == 2 and all(l.is_goal_reached() for l in self.levels):
                    # Add points for level three if all goals are reached in a non-bonus game.
                    total_score += level.get_points()

        # Return the total calculated score.
        return total_score

# Create three levels with points and goal status.
level1 = Level(100, True)
level2 = Level(150, True)
level3 = Level(200, True)

# Create a game with the levels and specify if it's a bonus game.
game = Game([level1, level2, level3], is_bonus=True)

# Calculate and print the score for the game.
score = game.get_score()
print(f"Game Score: {score}")

Game Score: 1350