Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import sys
- import random
- import collections
- # Initialize Pygame
- pygame.init()
- pygame.mixer.init()
- # Constants
- pygame.display.set_caption("Renis") # Set window title to "Renis"
- WINDOW_WIDTH = 300
- WINDOW_HEIGHT = 600
- BLOCK_SIZE = 30
- GRID_WIDTH = WINDOW_WIDTH // BLOCK_SIZE
- GRID_HEIGHT = WINDOW_HEIGHT // BLOCK_SIZE
- LEVEL_UP_SCORE = 1000 # Score needed to level up
- MIN_FALL_SPEED = 100 # Minimum fall speed in milliseconds
- FALL_SPEED_DECREMENT = 50 # Speed increase per level
- SCORING_RULES = {
- 1: 100,
- 2: 300,
- 3: 600,
- 4: 1000,
- }
- SCORE_INCREMENT = 100 # Kept for backward compatibility # Score increase for each cleared line
- # Colors
- WHITE = (255, 255, 255)
- BLUE = (0, 0, 255)
- BLACK = (0, 0, 0)
- # Sounds
- #rotate_sound = pygame.mixer.Sound("rotate.wav")
- #lock_sound = pygame.mixer.Sound("lock.wav")
- #hold_sound = pygame.mixer.Sound("hold.wav")
- #clear_sound = pygame.mixer.Sound("clear.wav")
- #renis_clear_sound = pygame.mixer.Sound("renisclear.wav")
- # Tetrimino shapes
- TETRIMINOS = {
- 'O': {'shape': [[1, 1],
- [1, 1]], 'color': (255, 255, 0)}, # Yellow
- 'I': {'shape': [[1, 1, 1, 1]], 'color': (0, 255, 255)}, # Cyan
- 'S': {'shape': [[0, 1, 1],
- [1, 1, 0]], 'color': (0, 255, 0)}, # Green
- 'Z': {'shape': [[1, 1, 0],
- [0, 1, 1]], 'color': (255, 0, 0)}, # Red
- 'L': {'shape': [[1, 1, 1],
- [1, 0, 0]], 'color': (255, 165, 0)}, # Orange
- 'J': {'shape': [[1, 1, 1],
- [0, 0, 1]], 'color': (0, 0, 255)}, # Blue
- 'T': {'shape': [[1, 1, 1],
- [0, 1, 0]], 'color': (128, 0, 128)}, # Purple
- }
- # To keep track of the last three generated pieces
- last_three_pieces = collections.deque(maxlen=3)
- # Initialize window
- window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
- def generate_tetrimino():
- while True:
- tetrimino_key = random.choice(list(TETRIMINOS.keys()))
- # Check if the new key is not repeating more than 3 times
- if last_three_pieces.count(tetrimino_key) < 3:
- break
- last_three_pieces.append(tetrimino_key) # Add the new key to the queue
- tetrimino_shape = TETRIMINOS[tetrimino_key]['shape']
- x_position = random.randint(0, GRID_WIDTH - len(tetrimino_shape[0]))
- return {'shape': tetrimino_shape, 'position': (x_position, 0), 'color': TETRIMINOS[tetrimino_key]['color']}
- def update_tetriminos(tetriminos):
- for tetrimino in tetriminos:
- x, y = tetrimino['position']
- tetrimino['position'] = (x, y + 1)
- tetriminos[:] = [t for t in tetriminos if t['position'][1] < GRID_HEIGHT]
- def draw_tetriminos(tetriminos, surface):
- for tetrimino in tetriminos:
- shape, (x, y), color = tetrimino['shape'], tetrimino['position'], tetrimino['color']
- draw_tetrimino(surface, shape, x * BLOCK_SIZE, y * BLOCK_SIZE, color)
- def draw_title_and_instructions(surface):
- title_font = pygame.font.SysFont(None, 72)
- instr_font = pygame.font.SysFont(None, 36)
- title_text = title_font.render('Renis', True, WHITE)
- instr_text = instr_font.render('Press any key to start', True, WHITE)
- title_rect = title_text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2 - 50))
- instr_rect = instr_text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2 + 50))
- surface.blit(title_text, title_rect)
- surface.blit(instr_text, instr_rect)
- def display_title_screen():
- # Load and play the music
- #pygame.mixer.music.load('title.mp3')
- #pygame.mixer.music.play(-1) # The -1 will make the music loop indefinitely running = True
- tetriminos = []
- last_generation_time = 0
- generation_interval = 1000
- while True:
- current_time = pygame.time.get_ticks()
- window.fill(BLACK)
- if current_time - last_generation_time > generation_interval:
- tetriminos.append(generate_tetrimino())
- last_generation_time = current_time
- update_tetriminos(tetriminos)
- draw_tetriminos(tetriminos, window)
- draw_title_and_instructions(window)
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- elif event.type == pygame.KEYDOWN:
- return
- pygame.time.delay(100)
- window.fill(BLACK) # Clearing the screen
- title_font = pygame.font.SysFont(None, 72) # Larger font for the title
- instr_font = pygame.font.SysFont(None, 36) # Smaller font for instructions
- title_text = title_font.render('Renis', True, WHITE)
- instr_text = instr_font.render('Press any key to start', True, WHITE)
- title_rect = title_text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2 - 50))
- instr_rect = instr_text.get_rect(center=(WINDOW_WIDTH // 2, WINDOW_HEIGHT // 2 + 50))
- window.blit(title_text, title_rect)
- window.blit(instr_text, instr_rect)
- pygame.display.flip() # Update the display
- def draw_transparent_block(surface, color, x, y, block_size, alpha=128):
- block = pygame.Surface((block_size, block_size), pygame.SRCALPHA)
- block.fill(color)
- block.set_alpha(alpha)
- surface.blit(block, (x, y))
- def draw_tetrimino(surface, shape, x, y, color, is_ghost=False, scale=1):
- for i, row in enumerate(shape):
- for j, block in enumerate(row):
- if block:
- scaled_block_size = int(BLOCK_SIZE * scale)
- if is_ghost:
- draw_transparent_block(surface, color, x + j*scaled_block_size, y + i*scaled_block_size, scaled_block_size)
- else:
- pygame.draw.rect(surface, color, (x + j*scaled_block_size, y + i*scaled_block_size, scaled_block_size, scaled_block_size))
- pygame.draw.rect(surface, WHITE, (x + j*scaled_block_size, y + i*scaled_block_size, scaled_block_size, scaled_block_size), 1) # Always draw white border
- #ghost tetrimino
- def get_ghost_position(tetrimino, x, y, grid):
- shape = tetrimino['shape']
- ghost_y = y
- # TODO: Replace 'collision' with your actual collision check function
- while not collision(shape, (x, ghost_y + 1), grid):
- ghost_y += 1
- return (x, ghost_y)
- #collision
- def collision(shape, position, grid):
- """
- Check if the space is occupied by the tetrimino.
- :param shape: 2D list representing the tetrimino shape.
- :param position: (x, y) position of the tetrimino.
- :param grid: 2D list representing the game grid.
- :return: Boolean value representing whether a collision occurred.
- """
- for i, row in enumerate(shape):
- for j, cell in enumerate(row):
- try:
- if cell and grid[i + position[1]][j + position[0]]:
- return True # Collision detected
- except IndexError: # Trying to access out of bounds index
- return True
- return False
- # Rotate the tetrimino
- def rotate_tetrimino(tetrimino, grid, x, y):
- shape = tetrimino['shape']
- rotated_shape = [
- [shape[x][y] for x in reversed(range(len(shape)))]
- for y in range(len(shape[0]))
- ]
- rotated_tetrimino = {'shape': rotated_shape, 'color': tetrimino['color']}
- x_move = 0
- y_move = 0
- original_y = y
- found_valid_position = False
- while y >= 0 and not found_valid_position:
- for x_offset in [0, -1, 1]:
- if is_valid_move(grid, rotated_tetrimino, x + x_offset, y):
- x_move = x_offset
- y_move = y - original_y
- found_valid_position = True
- break
- y -= 1
- if not found_valid_position:
- return tetrimino, 0, 0
- # Play rotation sound if the tetrimino was rotated
- if (rotated_tetrimino, x_move, y_move) != (tetrimino, 0, 0):
- #rotate_sound.play()
- return rotated_tetrimino, x_move, y_move
- # Counter-clockwise rotation
- def rotate_tetrimino_ccw(tetrimino, grid, x, y):
- shape = tetrimino['shape']
- rotated_shape = [
- [shape[x][y] for x in range(len(shape))]
- for y in reversed(range(len(shape[0])))
- ]
- rotated_tetrimino = {'shape': rotated_shape, 'color': tetrimino['color']}
- x_move, y_move = 0, 0
- if not is_valid_move(grid, rotated_tetrimino, x, y):
- if is_valid_move(grid, rotated_tetrimino, x + 1, y):
- x_move = 1
- elif is_valid_move(grid, rotated_tetrimino, x - 1, y):
- x_move = -1
- elif is_valid_move(grid, rotated_tetrimino, x, y - 1):
- y_move = -1
- else:
- return tetrimino, 0, 0
- # Play rotation sound if the tetrimino was rotated
- if (rotated_tetrimino, x_move, y_move) != (tetrimino, 0, 0):
- #rotate_sound.play()
- return rotated_tetrimino, x_move, y_move
- #Drop the Tetrimino to the bottom
- def hard_drop(current_tetrimino, current_x, current_y, current_grid):
- # Find how far the Tetrimino can drop
- while is_valid_move(current_grid, current_tetrimino, current_x, current_y + 1):
- current_y += 1
- # Return final position without altering the grid
- return current_x, current_y
- # Check if the new position/rotation is valid
- def is_valid_move(grid, tetrimino, x, y):
- for i, row in enumerate(tetrimino['shape']):
- for j, block in enumerate(row):
- if block:
- if (x + j < 0 or x + j >= GRID_WIDTH or
- y + i >= GRID_HEIGHT or grid[y + i][x + j]):
- return False
- return True
- # Merge the tetrimino into the grid and return the number of cleared lines
- def merge_tetrimino(grid, tetrimino, x, y):
- cleared_lines = 0
- for i, row in enumerate(tetrimino['shape']):
- for j, block in enumerate(row):
- if block:
- grid[y + i][x + j] = tetrimino['color']
- for i, row in enumerate(grid):
- if all(row):
- print(f"Clearing line {i}: {row}") # Debug log
- del grid[i]
- grid.insert(0, [0] * GRID_WIDTH)
- cleared_lines += 1
- # Play clear sound effects here
- if cleared_lines == 4: # If four lines are cleared, it's a Tetris!
- #renis_clear_sound.play()
- elif cleared_lines > 0: # If 1 to 3 lines are cleared
- #clear_sound.play()
- print(f"Cleared lines: {cleared_lines}") # Debug log
- return cleared_lines
- # Main loop
- def wait_for_key_press():
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- elif event.type == pygame.KEYDOWN:
- return
- def draw_text(surface, text, size, x, y, color):
- pygame.font.init() # You only need to call this once, so you might do it in the main part of your program
- font = pygame.font.Font(None, size) # Choose the font and size
- text_surface = font.render(text, True, color) # Create the text surface
- text_rect = text_surface.get_rect()
- text_rect.midtop = (x, y)
- surface.blit(text_surface, text_rect)
- def display_game_over_screen(final_score):
- # Load and play the music
- #pygame.mixer.music.load('gameover.mp3')
- #pygame.mixer.music.play(-1) # The -1 will make the music loop indefinitely running = True
- flying_tetriminos = []
- for _ in range(5):
- tetrimino_key = random.choice(list(TETRIMINOS.keys()))
- tetrimino = TETRIMINOS[tetrimino_key]
- while True:
- x = random.randint(0, WINDOW_WIDTH - len(tetrimino['shape'][0]) * BLOCK_SIZE)
- y = random.randint(-WINDOW_HEIGHT, WINDOW_HEIGHT//2)
- is_too_close = False
- for x_existing, y_existing, _ in flying_tetriminos:
- if abs(x - x_existing) < BLOCK_SIZE and abs(y - y_existing) < BLOCK_SIZE:
- is_too_close = True
- break
- if not is_too_close:
- break
- flying_tetriminos.append((x, y, tetrimino))
- clock = pygame.time.Clock()
- elapsed_time = 0
- input_enabled = False # Disable input initially
- input_enable_time = pygame.time.get_ticks() + 2000 # Enable input after 2000 ms (2 seconds)
- while True:
- window.fill(BLACK)
- elapsed_time += clock.tick(60)
- if elapsed_time >= 500:
- tetrimino_key = random.choice(list(TETRIMINOS.keys()))
- tetrimino = TETRIMINOS[tetrimino_key]
- x = random.randint(0, WINDOW_WIDTH - len(tetrimino['shape'][0]) * BLOCK_SIZE)
- y = -len(tetrimino['shape']) * BLOCK_SIZE
- flying_tetriminos.append((x, y, tetrimino))
- elapsed_time = 0
- for i, (x, y, tetrimino) in enumerate(flying_tetriminos):
- flying_tetriminos[i] = (x, y + 5, tetrimino)
- draw_tetrimino(window, tetrimino['shape'], x, y, tetrimino['color'])
- flying_tetriminos = [(x, y, tetrimino) for x, y, tetrimino in flying_tetriminos if y < WINDOW_HEIGHT]
- font = pygame.font.SysFont(None, 70)
- game_over_text = font.render('GAME OVER', True, WHITE)
- text_x = WINDOW_WIDTH // 2 - game_over_text.get_width() // 2
- text_y = WINDOW_HEIGHT // 2 - game_over_text.get_height() // 2 - 40
- window.blit(game_over_text, (text_x, text_y))
- score_label_font = pygame.font.SysFont(None, 50)
- score_label_text = score_label_font.render('Final Score:', True, WHITE)
- score_label_x = WINDOW_WIDTH // 2 - score_label_text.get_width() // 2
- score_label_y = WINDOW_HEIGHT // 2 - score_label_text.get_height() // 2
- window.blit(score_label_text, (score_label_x, score_label_y))
- score_value_font = pygame.font.SysFont(None, 50)
- score_value_text = score_value_font.render(str(final_score), True, WHITE)
- score_value_x = WINDOW_WIDTH // 2 - score_value_text.get_width() // 2
- score_value_y = score_label_y + score_label_text.get_height()
- window.blit(score_value_text, (score_value_x, score_value_y))
- pygame.display.flip()
- # Enable input after a delay
- if pygame.time.get_ticks() >= input_enable_time:
- input_enabled = True
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- elif event.type == pygame.KEYDOWN and input_enabled:
- # Check if the key is not the print screen key
- if event.key not in [pygame.K_PRINT, pygame.K_PRINTSCREEN]:
- return
- clock.tick(30)
- game_over_font = pygame.font.SysFont(None, 72)
- game_over_text = game_over_font.render("Game Over", True, WHITE)
- window.blit(game_over_text, (WINDOW_WIDTH // 2 - game_over_text.get_width() // 2, WINDOW_HEIGHT // 2 - game_over_text.get_height() // 2))
- pygame.display.update()
- def main_game():
- global LOCK_DELAY
- running = True
- # Load and play the music
- #pygame.mixer.music.load('renis.mp3')
- #pygame.mixer.music.play(-1) # The -1 will make the music loop indefinitely
- running = True
- grid = [[0] * GRID_WIDTH for _ in range(GRID_HEIGHT)]
- next_tetriminos = [TETRIMINOS[random.choice(list(TETRIMINOS.keys()))] for _ in range(3)]
- tetrimino = next_tetriminos.pop(0)
- held_tetrimino = None
- can_swap = True
- x, y = GRID_WIDTH // 2 - len(tetrimino['shape'][0]) // 2, 0
- clock = pygame.time.Clock()
- level = 1
- level_up_score = 1000
- fall_speed = 500
- LOCK_DELAY = 1.5
- fall_time = 0
- fall_speed -= (level-1) * 50
- move_speed = 150
- fast_fall_speed = 50
- last_move_time = 0
- last_fast_fall_time = 0
- score = 0
- lock_timer = 0 # Initialize lock timer
- while running:
- window.fill(WHITE)
- current_time = pygame.time.get_ticks()
- keys = pygame.key.get_pressed()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_x:
- # Clockwise rotation for UP and X keys
- rotated_tetrimino, x_move, y_move = rotate_tetrimino(tetrimino, grid, x, y)
- if is_valid_move(grid, rotated_tetrimino, x + x_move, y + y_move):
- tetrimino = rotated_tetrimino
- x += x_move
- y += y_move
- keys = pygame.key.get_pressed()
- lock_timer = 0 # Reset lock timer when Tetrimino moves down
- elif event.key == pygame.K_z:
- # Counter-clockwise rotation for Z key
- rotated_tetrimino, x_move, y_move = rotate_tetrimino_ccw(tetrimino, grid, x, y)
- if is_valid_move(grid, rotated_tetrimino, x + x_move, y + y_move):
- tetrimino = rotated_tetrimino
- x += x_move
- y += y_move
- keys = pygame.key.get_pressed()
- lock_timer = 0 # Reset lock timer when Tetrimino moves down
- elif event.key == pygame.K_SPACE:
- # Hard drop: Find the final position without altering the grid
- final_x, final_y = hard_drop(tetrimino, x, y, grid)
- # Merge and check for line clears
- cleared = merge_tetrimino(grid, tetrimino, final_x, final_y)
- #lock_sound.play()
- # Update score
- score += SCORING_RULES[cleared] if cleared in SCORING_RULES else cleared * SCORE_INCREMENT
- # Level up if needed
- if score >= level * level_up_score:
- print(f"Level Up: {level}")
- print(f"Fall Speed: {fall_speed}")
- level += 1
- level = min(level, 20) # Ensure the level does not exceed 20
- fall_speed = max(MIN_FALL_SPEED, fall_speed - FALL_SPEED_DECREMENT)
- # Generate new Tetrimino and check for game over
- tetrimino = next_tetriminos.pop(0)
- next_tetriminos.append(TETRIMINOS[random.choice(list(TETRIMINOS.keys()))])
- x, y = GRID_WIDTH // 2 - len(tetrimino['shape'][0]) // 2, 0
- # Allow swapping again
- can_swap = True
- if not is_valid_move(grid, tetrimino, x, y):
- running = False
- elif event.key == pygame.K_LSHIFT and can_swap:
- #hold_sound.play()
- print("Swapping...")
- if held_tetrimino:
- # Swap current and held Tetrimino
- tetrimino, held_tetrimino = held_tetrimino, tetrimino
- x, y = GRID_WIDTH // 2 - len(tetrimino['shape'][0]) // 2, 0
- else:
- # Hold the current Tetrimino and spawn a new one
- held_tetrimino = tetrimino
- tetrimino = next_tetriminos.pop(0)
- next_tetriminos.append(TETRIMINOS[random.choice(list(TETRIMINOS.keys()))])
- x, y = GRID_WIDTH // 2 - len(tetrimino['shape'][0]) // 2, 0
- can_swap = False # Prevent further swaps until a Tetrimino is placed
- print("can_swap set to False")
- elif event.key == pygame.K_r: # Check for R key press
- reset_game = True # Set the flag to True to indicate game reset
- running = False # Exit the game loop to end the function
- if (keys[pygame.K_LEFT] and
- is_valid_move(grid, tetrimino, x-1, y) and
- current_time - last_move_time > move_speed):
- x -= 1
- last_move_time = current_time
- lock_timer = 0 # Reset lock timer when Tetrimino moves down
- elif (keys[pygame.K_RIGHT] and
- is_valid_move(grid, tetrimino, x+1, y) and
- current_time - last_move_time > move_speed):
- x += 1
- last_move_time = current_time
- lock_timer = 0 # Reset lock timer when Tetrimino moves down
- elif (keys[pygame.K_DOWN] and
- is_valid_move(grid, tetrimino, x, y+1) and
- current_time - last_fast_fall_time > fast_fall_speed):
- y += 1
- last_fast_fall_time = current_time
- # Draw the held Tetrimino
- if held_tetrimino:
- draw_x = 10 # Adjust x to start drawing from left side
- draw_y = 80 # Adjust y to place it below Score and Level text
- draw_tetrimino(window, held_tetrimino['shape'], draw_x, draw_y, held_tetrimino['color'], scale=0.5)
- # Draw the grid
- for i, row in enumerate(grid):
- for j, block in enumerate(row):
- if block:
- pygame.draw.rect(window, block, (j*BLOCK_SIZE, i*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE))
- pygame.draw.rect(window, WHITE, (j*BLOCK_SIZE, i*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE), 1)
- # Drawing the ghost Tetrimino
- ghost_x, ghost_y = get_ghost_position(tetrimino, x, y, grid)
- draw_tetrimino(window, tetrimino['shape'], ghost_x * BLOCK_SIZE, ghost_y * BLOCK_SIZE, tetrimino['color'], is_ghost=True)
- # Drawing the active Tetrimino
- draw_tetrimino(window, tetrimino['shape'], x * BLOCK_SIZE, y * BLOCK_SIZE, tetrimino['color'], is_ghost=False)
- # Draw the score
- font = pygame.font.SysFont(None, 36)
- score_text = font.render(f'Score: {score}', True, BLACK)
- window.blit(score_text, (10, 10))
- # Draw the level
- level_text = font.render(f'Level: {level}', True, BLACK)
- window.blit(level_text, (10, 40))
- # Draw the next Tetrimino from the queue
- next_tetrimino = next_tetriminos[0]
- draw_x = GRID_WIDTH * BLOCK_SIZE - 2 * BLOCK_SIZE
- draw_y = 0
- draw_tetrimino(window, next_tetrimino['shape'], draw_x, draw_y, next_tetrimino['color'], scale=0.5, is_ghost=False)
- # Update the display
- pygame.display.flip()
- # Control the falling speed of the tetrimino
- fall_time += clock.get_rawtime()
- clock.tick()
- if fall_time > fall_speed:
- if is_valid_move(grid, tetrimino, x, y+1):
- y += 1
- lock_timer = 0 # Reset lock timer when Tetrimino moves down
- else:
- lock_timer += clock.get_rawtime() # Increment lock timer
- print(f"Incrementing Lock Timer: {lock_timer}") # Debug print
- if lock_timer >= LOCK_DELAY: # Check if lock timer has reached threshold
- print("Locking Tetrimino") # Debug print
- # Merge, check for line clears, generate new Tetrimino, etc.
- cleared = merge_tetrimino(grid, tetrimino, x, y)
- # PLAY LOCK SOUND HERE
- #lock_sound.play()
- print(f"Cleared Lines: {cleared}") # Debugging: Check cleared lines value
- print(f"Score Before Update: {score}") # Debugging: Check score before update
- score += SCORING_RULES[cleared] if cleared in SCORING_RULES else cleared * SCORE_INCREMENT
- print(f"Score After Update: {score}") # Debugging: Check score after update
- if score >= level * level_up_score:
- level += 1
- level = min(level, 20) # Ensure the level does not exceed 20
- print(f"Level Up: {level}")
- print(f"Fall Speed: {fall_speed}")
- print(f"Lock Delay: {LOCK_DELAY}")
- fall_speed = max(MIN_FALL_SPEED, fall_speed - FALL_SPEED_DECREMENT)
- tetrimino = next_tetriminos.pop(0)
- next_tetriminos.append(TETRIMINOS[random.choice(list(TETRIMINOS.keys()))])
- x, y = GRID_WIDTH // 2 - len(tetrimino['shape'][0]) // 2, 0
- if not is_valid_move(grid, tetrimino, x, y):
- running = False
- can_swap = True
- lock_timer = 0 # Reset lock timer after locking Tetrimino
- fall_time = 0
- final_score = score
- # Define a dictionary that maps levels to LOCK_DELAY values
- lock_delay_map = {
- 1: 2.5,
- 2: 3,
- 3: 3,
- 4: 4,
- 5: 4,
- 6: 4,
- 7: 5,
- 8: 6,
- 9: 8,
- 10: 8,
- 11: 8,
- 12: 8,
- 13: 9,
- 14: 9,
- 15: 9,
- 16: 9,
- 17: 10,
- 18: 10,
- 19: 10,
- 20: 10
- }
- # Get the LOCK_DELAY value using the level as a key, if it exists in the dictionary
- LOCK_DELAY = lock_delay_map.get(level)
- #pygame.mixer.music.stop()
- reset_game = False
- return final_score, reset_game # Return the status of the reset_game flag
- if __name__ == "__main__":
- while True:
- display_title_screen()
- final_score, reset_game = main_game() # Assume main_game returns a tuple (reset_flag, score)
- #if not reset_game:
- display_game_over_screen(final_score)
- # If reset_game is True, the loop will repeat, restarting the game
Advertisement
Add Comment
Please, Sign In to add comment