master
parent
e17db93158
commit
4c0f817be3
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.analysis.typeCheckingMode": "off"
|
||||||
|
}
|
54
main.py
54
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)
|
puzzle_matrix[min(clicked_row, zero_row):max(clicked_row, zero_row) + 1, clicked_col] = np.roll(pieces_to_move, 1)
|
||||||
elif direction == "up":
|
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]]
|
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()
|
save_puzzle_state()
|
||||||
update_directions()
|
update_directions()
|
||||||
|
return pieces_to_move.any()
|
||||||
|
|
||||||
|
|
||||||
def update_directions():
|
def update_directions():
|
||||||
|
@ -746,17 +746,22 @@ else:
|
||||||
ver1_layer = sprite_sheet.get_sprite((399, 156), WIDTH, HEIGHT, transparent)
|
ver1_layer = sprite_sheet.get_sprite((399, 156), WIDTH, HEIGHT, transparent)
|
||||||
ver2_layer = sprite_sheet.get_sprite((798, 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:]
|
def load_data():
|
||||||
current_data = storage["albums"][path_components[0]]
|
path_components = puzzle_data[f'current {puzzle_version}']['selected_image'].split('/')[2:]
|
||||||
for component in path_components[1:]:
|
current_data = storage["albums"][path_components[0]]
|
||||||
current_data = current_data[component]
|
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]
|
return completed, not_shuffled, timer_text, current_timer_text, displayed_current_moves, current_moves
|
||||||
not_shuffled = current_data[2]
|
|
||||||
timer_text = current_data[5]
|
completed, not_shuffled, timer_text, current_timer_text, displayed_current_moves, current_moves = load_data()
|
||||||
current_timer_text = timer_text
|
|
||||||
current_moves = current_data[6]
|
|
||||||
|
|
||||||
if completed:
|
if completed:
|
||||||
state_button = finished_button
|
state_button = finished_button
|
||||||
|
@ -832,7 +837,7 @@ def data_check(current_mode):
|
||||||
current_buttons = menu_buttons
|
current_buttons = menu_buttons
|
||||||
background_image = ver1_layer
|
background_image = ver1_layer
|
||||||
|
|
||||||
elif current_mode == "settings":
|
elif current_mode == "settings" or current_mode == "stats" or current_mode == "info":
|
||||||
current_buttons = settings_buttons
|
current_buttons = settings_buttons
|
||||||
background_image = ver1_layer
|
background_image = ver1_layer
|
||||||
|
|
||||||
|
@ -853,13 +858,14 @@ dragging = False
|
||||||
can_move = False
|
can_move = False
|
||||||
start_pos = (0, 0)
|
start_pos = (0, 0)
|
||||||
pressed_button = None
|
pressed_button = None
|
||||||
clicked_piece = False
|
|
||||||
# Select mode
|
# Select mode
|
||||||
clicked_image = False
|
clicked_image = False
|
||||||
image_display = None
|
image_display = None
|
||||||
|
clicked = None
|
||||||
# Puzzle-related stuff
|
# Puzzle-related stuff
|
||||||
last_shuffle_time = 0
|
last_shuffle_time = 0
|
||||||
user_win = False
|
user_win = False
|
||||||
|
moved = None
|
||||||
# Timer-related stuff
|
# Timer-related stuff
|
||||||
timer_running = False
|
timer_running = False
|
||||||
timer_start_time = 0
|
timer_start_time = 0
|
||||||
|
@ -898,8 +904,7 @@ while run:
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
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)
|
update_puzzle_data(completed, not_shuffled, current_timer_text, current_moves, real_time)
|
||||||
reload_chosen()
|
reload_chosen()
|
||||||
run = False
|
run = False
|
||||||
|
@ -910,8 +915,14 @@ while run:
|
||||||
clicked_image_rect = ImageRender.image_save(selected_album, current_img)
|
clicked_image_rect = ImageRender.image_save(selected_album, current_img)
|
||||||
clicked_image = clicked_image_rect.collidepoint(event.pos)
|
clicked_image = clicked_image_rect.collidepoint(event.pos)
|
||||||
if clicked_image:
|
if clicked_image:
|
||||||
|
clicked = True
|
||||||
current_mode = "game"
|
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)
|
shuffle_pieces(puzzle_pieces)
|
||||||
|
clicked = None
|
||||||
last_click_time = pygame.time.get_ticks()
|
last_click_time = pygame.time.get_ticks()
|
||||||
|
|
||||||
if to_left_button.is_hovered(event.pos):
|
if to_left_button.is_hovered(event.pos):
|
||||||
|
@ -950,7 +961,6 @@ while run:
|
||||||
elif event.type == pygame.MOUSEBUTTONUP:
|
elif event.type == pygame.MOUSEBUTTONUP:
|
||||||
dragging = False
|
dragging = False
|
||||||
pressed_button = None
|
pressed_button = None
|
||||||
clicked_piece = False
|
|
||||||
can_move = False
|
can_move = False
|
||||||
|
|
||||||
elif event.type == pygame.MOUSEBUTTONDOWN and current_mode == "settings":
|
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
|
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 0 <= clicked_row < len(puzzle_matrix) and 0 <= clicked_col < len(puzzle_matrix[0]):
|
||||||
if puzzle_matrix[clicked_row, clicked_col]:
|
if puzzle_matrix[clicked_row, clicked_col] and clicked is None:
|
||||||
user_win = True
|
moved = move_pieces(clicked_row, clicked_col)
|
||||||
current_moves += 1
|
print(current_mode, clicked)
|
||||||
move_pieces(clicked_row, clicked_col)
|
if settings_data["sound"]["on"] is True and moved is not None:
|
||||||
clicked_piece = True
|
current_moves += 1
|
||||||
if settings_data["sound"]["on"] is True and clicked_piece is True:
|
user_win = True
|
||||||
print("clicked")
|
print("clicked:", current_moves)
|
||||||
play_sound()
|
play_sound()
|
||||||
|
|
||||||
if pressed_button == hint_button:
|
if pressed_button == hint_button:
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
1094,
|
16,
|
||||||
"00:00:11",
|
"00:00:11",
|
||||||
"00:00:11",
|
"00:00:11",
|
||||||
16
|
16
|
||||||
|
|
|
@ -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"}}
|
{"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"}}
|
Loading…
Reference in New Issue