diff options
Diffstat (limited to 'puzzle.cpp')
-rw-r--r-- | puzzle.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -1,10 +1,13 @@ #include "puzzle.hpp" +#include "gameplay.hpp" #include <stdlib.h> #include <string> #include <FL/Fl_JPEG_Image.H> +#include <utility> +#include <memory> -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<Puzzle> 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<Puzzle>(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); } |