From 4c0f817be3e48244e71a35c7c5738cd67f242de9 Mon Sep 17 00:00:00 2001 From: elukjanovica Date: Fri, 1 Mar 2024 18:34:30 +0200 Subject: [PATCH] --- .vscode/settings.json | 3 +++ main.py | 54 +++++++++++++++++++++++++------------------ main_data.json | 2 +- main_puzzle.json | 2 +- 4 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a6735e5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.analysis.typeCheckingMode": "off" +} \ No newline at end of file diff --git a/main.py b/main.py index 4ac977b..c9ce8b7 100644 --- a/main.py +++ b/main.py @@ -540,9 +540,9 @@ def move_pieces(clicked_row, clicked_col): puzzle_matrix[min(clicked_row, zero_row):max(clicked_row, zero_row) + 1, clicked_col] = np.roll(pieces_to_move, 1) elif direction == "up": puzzle_matrix[min(clicked_row, zero_row):max(clicked_row, zero_row) + 1, clicked_col] = np.roll(pieces_to_move, -1)[:pieces_to_move.shape[0]] - save_puzzle_state() update_directions() + return pieces_to_move.any() def update_directions(): @@ -746,17 +746,22 @@ else: ver1_layer = sprite_sheet.get_sprite((399, 156), WIDTH, HEIGHT, transparent) ver2_layer = sprite_sheet.get_sprite((798, 156), WIDTH, HEIGHT, transparent) -path_components = puzzle_data[f'current {puzzle_version}']['selected_image'].split('/')[2:] -current_data = storage["albums"][path_components[0]] -for component in path_components[1:]: - current_data = current_data[component] +def load_data(): + path_components = puzzle_data[f'current {puzzle_version}']['selected_image'].split('/')[2:] + current_data = storage["albums"][path_components[0]] + for component in path_components[1:]: + current_data = current_data[component] + completed = current_data[1] + not_shuffled = current_data[2] + timer_text = current_data[5] + current_timer_text = timer_text + displayed_current_moves = current_data[6] + current_moves = 0 -completed = current_data[1] -not_shuffled = current_data[2] -timer_text = current_data[5] -current_timer_text = timer_text -current_moves = current_data[6] + return completed, not_shuffled, timer_text, current_timer_text, displayed_current_moves, current_moves + +completed, not_shuffled, timer_text, current_timer_text, displayed_current_moves, current_moves = load_data() if completed: state_button = finished_button @@ -832,7 +837,7 @@ def data_check(current_mode): current_buttons = menu_buttons background_image = ver1_layer - elif current_mode == "settings": + elif current_mode == "settings" or current_mode == "stats" or current_mode == "info": current_buttons = settings_buttons background_image = ver1_layer @@ -853,13 +858,14 @@ dragging = False can_move = False start_pos = (0, 0) pressed_button = None -clicked_piece = False # Select mode clicked_image = False image_display = None +clicked = None # Puzzle-related stuff last_shuffle_time = 0 user_win = False +moved = None # Timer-related stuff timer_running = False timer_start_time = 0 @@ -898,8 +904,7 @@ while run: for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - if current_mode == "game": #is this needed? - save_puzzle_state() + save_puzzle_state() update_puzzle_data(completed, not_shuffled, current_timer_text, current_moves, real_time) reload_chosen() run = False @@ -910,8 +915,14 @@ while run: clicked_image_rect = ImageRender.image_save(selected_album, current_img) clicked_image = clicked_image_rect.collidepoint(event.pos) if clicked_image: + clicked = True current_mode = "game" + update_puzzle_data(completed, not_shuffled, current_timer_text, current_moves, real_time) + print(current_timer_text) + completed, not_shuffled, timer_text, current_timer_text, displayed_current_moves, current_moves = load_data() + print(current_timer_text) shuffle_pieces(puzzle_pieces) + clicked = None last_click_time = pygame.time.get_ticks() if to_left_button.is_hovered(event.pos): @@ -950,7 +961,6 @@ while run: elif event.type == pygame.MOUSEBUTTONUP: dragging = False pressed_button = None - clicked_piece = False can_move = False elif event.type == pygame.MOUSEBUTTONDOWN and current_mode == "settings": @@ -999,13 +1009,13 @@ while run: clicked_row, clicked_col = (mouse_y - non_movable_area.y) // cell_size, (mouse_x - non_movable_area.x) // cell_size if 0 <= clicked_row < len(puzzle_matrix) and 0 <= clicked_col < len(puzzle_matrix[0]): - if puzzle_matrix[clicked_row, clicked_col]: - user_win = True - current_moves += 1 - move_pieces(clicked_row, clicked_col) - clicked_piece = True - if settings_data["sound"]["on"] is True and clicked_piece is True: - print("clicked") + if puzzle_matrix[clicked_row, clicked_col] and clicked is None: + moved = move_pieces(clicked_row, clicked_col) + print(current_mode, clicked) + if settings_data["sound"]["on"] is True and moved is not None: + current_moves += 1 + user_win = True + print("clicked:", current_moves) play_sound() if pressed_button == hint_button: diff --git a/main_data.json b/main_data.json index 9a6adb6..1ca6cb9 100644 --- a/main_data.json +++ b/main_data.json @@ -5,7 +5,7 @@ 0, 0, 0, - 1094, + 16, "00:00:11", "00:00:11", 16 diff --git a/main_puzzle.json b/main_puzzle.json index 3c04bfb..7d3783d 100644 --- a/main_puzzle.json +++ b/main_puzzle.json @@ -1 +1 @@ -{"puzzle 4x4": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "puzzle 3x3": [[1, 2, 3], [4, 5, 6], [7, 8, 0]], "current 4x4": {"matrix": [[4, 9, 7, 0], [13, 1, 8, 3], [2, 12, 5, 11], [15, 14, 6, 10]], "selected_image": "images/albums/Original images/1.png"}, "current 3x3": {"matrix": [[3, 6, 7], [5, 4, 1], [0, 8, 2]], "selected_image": "/images/albums/Birds/1.png"}} \ No newline at end of file +{"puzzle 4x4": [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]], "puzzle 3x3": [[1, 2, 3], [4, 5, 6], [7, 8, 0]], "current 4x4": {"matrix": [[12, 15, 10, 4], [14, 11, 9, 5], [2, 6, 1, 0], [7, 8, 3, 13]], "selected_image": "images/albums/Original images/3.png"}, "current 3x3": {"matrix": [[3, 6, 7], [5, 4, 1], [0, 8, 2]], "selected_image": "/images/albums/Birds/1.png"}} \ No newline at end of file