From e64c2a9d94bb6e21ac24d7e1ff5915a29bbd67bf Mon Sep 17 00:00:00 2001 From: scratko Date: Sat, 9 Nov 2024 20:00:19 +0300 Subject: Moving slides Changed to 8 puzzles Added reaction to clicking a puzzle Puzzles are moved to vector --- puzzle.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'puzzle.cpp') diff --git a/puzzle.cpp b/puzzle.cpp index 6d7d635..0e3574b 100644 --- a/puzzle.cpp +++ b/puzzle.cpp @@ -1,10 +1,13 @@ #include "puzzle.hpp" +#include "gameplay.hpp" #include #include #include +#include +#include -void GameParams::CalculatePuzzlePos() +void GameParams::CalculateStandardPuzzlePos() { coordinates tmp; @@ -15,7 +18,7 @@ void GameParams::CalculatePuzzlePos() break; tmp.x = i * (puzzle_size + spacing) + spacing; tmp.y = j * (puzzle_size + spacing) + spacing; - puzzle_coordinates[k] = tmp; + standard_puzzle_coordinates[k] = tmp; } } @@ -35,29 +38,32 @@ static void find_path_to_picture(std::string& path, int number) void GameParams::CreateNewPuzzles() { int idx_random_puzzle; + std::unique_ptr tmp_puzzle; /* * check if puzzles already were created */ - for(int i = 0; i < puzzle_pieces; ++i) - if(puzzles[i]) - delete puzzles[i]; + if(puzzles.size() != 0) + puzzles.clear(); /* * ======== creating puzzles =========== */ for(int i = 0; i < puzzle_pieces; ++i) { - puzzles[i] = - new Puzzle(puzzle_coordinates[i].x, puzzle_coordinates[i].y); + tmp_puzzle = + std::unique_ptr(new Puzzle(standard_puzzle_coordinates[i].x, + standard_puzzle_coordinates[i].y)); idx_random_puzzle = 0 + (int)((double)puzzle_pieces * rand()/(RAND_MAX + 1.0)); while(!free_puzzles[idx_random_puzzle]) idx_random_puzzle = 0 + (int)((double)puzzle_pieces * rand()/(RAND_MAX + 1.0)); free_puzzles[idx_random_puzzle] = 0; - puzzles[i]->sequence_number = idx_random_puzzle; - find_path_to_picture(puzzles[i]->path, puzzles[i]->sequence_number); - Fl_JPEG_Image *img = new Fl_JPEG_Image(puzzles[i]->path.c_str()); + tmp_puzzle->sequence_number = idx_random_puzzle; + find_path_to_picture(tmp_puzzle->path, tmp_puzzle->sequence_number); + Fl_JPEG_Image *img = new Fl_JPEG_Image(tmp_puzzle->path.c_str()); // TODO check fails img->fail(); - puzzles[i]->image(img); + tmp_puzzle->image(img); + tmp_puzzle->callback(press_button_callback, this); + puzzles.push_back(std::move(tmp_puzzle)); } } @@ -65,4 +71,5 @@ void GameParams::NewGame() { ResetFreePuzzles(); CreateNewPuzzles(); + SetXYEmptyBox(215, 215); } -- cgit v1.2.3