OmerKSonmez / ISP-Project

0 stars 0 forks source link

Task: Fix Restart / New Game #42

Closed OmerKSonmez closed 7 months ago

OmerKSonmez commented 7 months ago

Currently, the game malfunctions when the "Restart Game" button is pressed. In order to fix this issue, I will have to debug the code and improvise.

31

OmerKSonmez commented 7 months ago

def restart_game(): global paddle, ball, ball_speed, bricks, score, lives, game_over paddle = pygame.Rect((WIDTH - PADDLE_WIDTH) // 2, HEIGHT - PADDLE_HEIGHT - 10, PADDLE_WIDTH, PADDLE_HEIGHT) ball = pygame.Rect(WIDTH // 2 - BALL_RADIUS, HEIGHT // 2 - BALL_RADIUS, BALL_RADIUS 2, BALL_RADIUS 2) ball_speed = [2, 2]

colors = [RED, BLUE, GREEN]
bricks = []
for row in range(5):
    for col in range(WIDTH // BRICK_WIDTH):
        brick_color = random.choice(colors)
        brick = pygame.Rect(col * BRICK_WIDTH, row * BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT)
        bricks.append((brick, brick_color))

score = 0
lives = LIVES
game_over = False

... (remaining code remains unchanged)

Main game loop

while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_r and game_over: # Restart game with 'R' key restart_game()

if not game_over:
    # ... (remaining code remains unchanged)